--- libsmartcols/src/table_print.c 2014-12-24 23:59:55.780110296 +0200 +++ libsmartcols/src/table_print.c 2014-12-28 22:45:20.347285226 +0200 @@ -151,6 +151,32 @@ return bytes; } +/* returns pointer to the end of used data */ +static int line_ascii_art_to_buffer(struct libscols_table *tb, + struct libscols_line *ln, + struct libscols_buffer *buf) +{ + const char *art; + int rc; + + assert(ln); + assert(buf); + + if (!ln->parent) + return 0; + + rc = line_ascii_art_to_buffer(tb, ln->parent, buf); + if (rc) + return rc; + + if (list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch)) + art = " "; + else + art = tb->symbols->vert; + + return buffer_append_data(buf, art); +} + #define is_last_column(_tb, _cl) \ list_entry_is_last(&(_cl)->cl_columns, &(_tb)->tb_columns) @@ -258,8 +284,33 @@ if (len > width && !scols_column_is_trunc(cl)) { fputs(linesep(tb), tb->out); for (i = 0; i <= (size_t) cl->seqnum; i++) { - struct libscols_column *x = scols_table_get_column(tb, i); - fprintf(tb->out, "%*s ", -((int)x->width), " "); + size_t len_pad = 0; /* in screen cells as opposed to bytes */ + struct libscols_column* cl_pad = scols_table_get_column(tb, i); + if(ln && scols_column_is_tree(cl_pad)) { + if (!ln->parent) { /* Root cell needs special treatment. */ + if (!list_empty(&ln->ln_branch)) { /* only print symbols->vert if followed by something */ + fputs(tb->symbols->vert, tb->out); + len_pad = mbs_safe_width(tb->symbols->vert); + } + } else { /* use the same draw function as though we were intending to draw an L-shape */ + struct libscols_buffer* b_art = new_buffer(1024); /* TODO: FIXME proper size */ + char* data = 0; + + if(b_art) { + line_ascii_art_to_buffer(tb, ln, b_art); /* whatever the rc, len_pad will be sensible */ + data = buffer_get_safe_data(b_art, &len_pad); + if(data && len_pad) { + fputs(data, tb->out); + } + + free_buffer(b_art); + } + } + } + for(; len_pad <= cl_pad->width; ++len_pad) + { + fputc(' ', tb->out); + } } } else fputs(colsep(tb), tb->out); /* columns separator */ @@ -268,32 +319,6 @@ return 0; } -/* returns pointer to the end of used data */ -static int line_ascii_art_to_buffer(struct libscols_table *tb, - struct libscols_line *ln, - struct libscols_buffer *buf) -{ - const char *art; - int rc; - - assert(ln); - assert(buf); - - if (!ln->parent) - return 0; - - rc = line_ascii_art_to_buffer(tb, ln->parent, buf); - if (rc) - return rc; - - if (list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch)) - art = " "; - else - art = tb->symbols->vert; - - return buffer_append_data(buf, art); -} - static int cell_to_buffer(struct libscols_table *tb, struct libscols_line *ln, struct libscols_column *cl,