diff options
author | Igor Gnatenko <i.gnatenko.brain@gmail.com> | 2016-01-22 14:29:16 +0100 |
---|---|---|
committer | Igor Gnatenko <i.gnatenko.brain@gmail.com> | 2016-01-22 14:29:16 +0100 |
commit | e6f89163be323b72ebb33b456671195ca51e02c4 (patch) | |
tree | 48a5d4599366ff53faebd37261eee84b7abe31c6 /libsmartcols | |
parent | a64040930960699e1457dcface8334c501ba96a6 (diff) | |
download | util-linux-e6f89163be323b72ebb33b456671195ca51e02c4.tar.gz |
libsmartcols: wrap columns correctly with unicode
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r-- | libsmartcols/src/table_print.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index f1b0d5965..b67640751 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -352,15 +352,25 @@ static int print_data(struct libscols_table *tb, if (color) fputs(UL_COLOR_RESET, tb->out); len = width; - } else if (scols_column_is_wrap(cl)) { + } else if (len > width && scols_column_is_wrap(cl)) { char *p = data; + i = 0; while (*p) { - fprintf(tb->out, "%.*s", (int) width, p); - p += width; + len = width; + p = strdup(p); + bytes = mbs_truncate(p, &len); + if (bytes == (size_t) -1) { + free(p); + break; + } + fputs(p, tb->out); + free(p); + i += bytes; + p = data + i; if (*p) - for (i = 0; i < cl->seqnum; i++) - print_empty_cell (tb, scols_table_get_column(tb, i), + for (size_t j = 0; j < cl->seqnum; j++) + print_empty_cell (tb, scols_table_get_column(tb, j), NULL, buf->bufsz); } } else if (color) { |