diff options
author | Igor Gnatenko <i.gnatenko.brain@gmail.com> | 2016-01-21 09:57:31 +0100 |
---|---|---|
committer | Igor Gnatenko <i.gnatenko.brain@gmail.com> | 2016-01-22 12:51:45 +0100 |
commit | a64040930960699e1457dcface8334c501ba96a6 (patch) | |
tree | 6af1a0dc0f5b7a4499218cee1d48d65c6e6b43f5 /libsmartcols | |
parent | acde3a05a92ddd39234c89e55b654cd7b8058656 (diff) | |
download | util-linux-a64040930960699e1457dcface8334c501ba96a6.tar.gz |
libsmartcols: implement SCOLS_FL_WRAP
Reference: https://github.com/karelzak/util-linux/issues/257
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Diffstat (limited to 'libsmartcols')
-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 | 14 |
4 files changed, 30 insertions, 1 deletions
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index b31b39063..a9891d7f5 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -350,3 +350,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 0331f3713..607086a92 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 */ }; extern struct libscols_iter *scols_new_iter(int direction); @@ -129,6 +130,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 e1e4382eb..b90cefabe 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_table_enable_nowrap; diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index 8c08e5026..f1b0d5965 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -327,7 +327,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 */ @@ -351,6 +352,17 @@ 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)) { + char *p = data; + + while (*p) { + fprintf(tb->out, "%.*s", (int) width, p); + p += width; + if (*p) + for (i = 0; i < cl->seqnum; i++) + print_empty_cell (tb, scols_table_get_column(tb, i), + NULL, buf->bufsz); + } } else if (color) { char *p = data; size_t art = buffer_get_safe_art_size(buf); |