diff options
author | Karel Zak | 2016-01-25 13:03:29 +0100 |
---|---|---|
committer | Karel Zak | 2016-01-25 13:03:29 +0100 |
commit | d372bcf26e25ebe7a3264e01cbc328d3a81e7a12 (patch) | |
tree | b8fdc85534f9e3e60b7d1ba9d2c2a6d359cc3cb0 /libsmartcols | |
parent | libsmartcols: document v2.27 symbols (diff) | |
parent | libsmartcols: add scols_column_is_wrap to docs (diff) | |
download | kernel-qcow2-util-linux-d372bcf26e25ebe7a3264e01cbc328d3a81e7a12.tar.gz kernel-qcow2-util-linux-d372bcf26e25ebe7a3264e01cbc328d3a81e7a12.tar.xz kernel-qcow2-util-linux-d372bcf26e25ebe7a3264e01cbc328d3a81e7a12.zip |
Merge branch 'scols_fl_wrap' of https://github.com/ignatenkobrain/util-linux
* 'scols_fl_wrap' of https://github.com/ignatenkobrain/util-linux:
libsmartcols: add scols_column_is_wrap to docs
libsmartcols: don't loose colors when wrapping
libsmartcols: wrap columns correctly with unicode
libsmartcols: implement SCOLS_FL_WRAP
Diffstat (limited to 'libsmartcols')
-rw-r--r-- | libsmartcols/docs/libsmartcols-sections.txt | 1 | ||||
-rw-r--r-- | libsmartcols/src/column.c | 14 | ||||
-rw-r--r-- | libsmartcols/src/libsmartcols.h.in | 2 | ||||
-rw-r--r-- | libsmartcols/src/libsmartcols.sym | 1 | ||||
-rw-r--r-- | libsmartcols/src/table_print.c | 30 |
5 files changed, 47 insertions, 1 deletions
diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt index 9334a7e99..44856e1b1 100644 --- a/libsmartcols/docs/libsmartcols-sections.txt +++ b/libsmartcols/docs/libsmartcols-sections.txt @@ -26,6 +26,7 @@ scols_column_is_right scols_column_is_strict_width scols_column_is_tree scols_column_is_trunc +scols_column_is_wrap scols_column_set_cmpfunc scols_column_set_color scols_column_set_flags diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index a01c0b599..047373024 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -352,3 +352,17 @@ int scols_column_is_noextremes(struct libscols_column *cl) return -EINVAL; return cl->flags & SCOLS_FL_NOEXTREMES; } +/** + * scols_column_is_wrap: + * @cl: a pointer to a struct libscols_column instance + * + * Gets the value of @cl's flag wrap. + * + * Returns: wrap flag value, negative value in case of an error. + */ +int scols_column_is_wrap(struct libscols_column *cl) +{ + if (!cl) + return -EINVAL; + return cl->flags & SCOLS_FL_WRAP; +} diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 573a6ddca..9849a2cfb 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -84,6 +84,7 @@ enum { SCOLS_FL_STRICTWIDTH = (1 << 3), /* don't reduce width if column is empty */ SCOLS_FL_NOEXTREMES = (1 << 4), /* ignore extreme fields when count column width*/ SCOLS_FL_HIDDEN = (1 << 5), /* maintain data, but don't print */ + SCOLS_FL_WRAP = (1 << 6), /* wrap long cells across lines */ }; /* @@ -139,6 +140,7 @@ extern int scols_column_is_right(struct libscols_column *cl); extern int scols_column_is_strict_width(struct libscols_column *cl); extern int scols_column_is_hidden(struct libscols_column *cl); extern int scols_column_is_noextremes(struct libscols_column *cl); +extern int scols_column_is_wrap(struct libscols_column *cl); extern int scols_column_set_flags(struct libscols_column *cl, int flags); extern int scols_column_get_flags(struct libscols_column *cl); diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym index 8e298eb48..c79d87c71 100644 --- a/libsmartcols/src/libsmartcols.sym +++ b/libsmartcols/src/libsmartcols.sym @@ -124,6 +124,7 @@ global: SMARTCOLS_2.28 { global: + scols_column_is_wrap; scols_line_refer_column_data; scols_line_set_column_data; scols_symbols_set_title_padding; diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 6f2ece7d3..02d9462d5 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -328,7 +328,8 @@ static int print_data(struct libscols_table *tb, if (is_last_column(tb, cl) && len < width && !scols_table_is_maxout(tb) - && !scols_column_is_right(cl)) + && !scols_column_is_right(cl) + && !scols_column_is_wrap(cl)) width = len; /* truncate data */ @@ -352,6 +353,33 @@ static int print_data(struct libscols_table *tb, if (color) fputs(UL_COLOR_RESET, tb->out); len = width; + } else if (len > width && scols_column_is_wrap(cl)) { + char *p = data; + i = 0; + + if (color) + fputs(color, tb->out); + + while (*p) { + 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 (size_t j = 0; j < cl->seqnum; j++) + print_empty_cell (tb, scols_table_get_column(tb, j), + NULL, buf->bufsz); + } + + if (color) + fputs(UL_COLOR_RESET, tb->out); } else if (color) { char *p = data; size_t art = buffer_get_safe_art_size(buf); |