summaryrefslogtreecommitdiffstats
path: root/libsmartcols/samples/fromfile.c
diff options
context:
space:
mode:
authorKarel Zak2016-09-26 11:20:07 +0200
committerKarel Zak2016-09-26 11:20:07 +0200
commit949ea05f1af647834db24b9172ac006488d2e4f4 (patch)
tree0e735393ebe57f1f53cab8da3288b96fcc756f27 /libsmartcols/samples/fromfile.c
parentlibsmartcols: (docs) add missing functions (diff)
downloadkernel-qcow2-util-linux-949ea05f1af647834db24b9172ac006488d2e4f4.tar.gz
kernel-qcow2-util-linux-949ea05f1af647834db24b9172ac006488d2e4f4.tar.xz
kernel-qcow2-util-linux-949ea05f1af647834db24b9172ac006488d2e4f4.zip
libsmartcols: support custom wrap and remove SCOLS_FL_WRAPNL
This new API provides full control on multi-line cells, you can wrap text by new lines (build-in support) or by another way (after words, commas, etc.) Changes: * new scols_column_set_wrapfunc() sets pointers to two callback functions 1/ chunksize() - returns largest data chunk size; used when we calculate columns width 2/ nextchunk() - terminate the current chunk and returns pointer to the next; used when we print data * remove SCOLS_FL_WRAPNL and add new functions scols_wrapnl_chunksize() and scols_wrapnl_nextchunk() to provide build-in functionality to wrap cells on \n * remove scols_column_is_wrapnl() add scols_column_is_customwrap() (returns true if custom wrap functions are defined) * add scols_column_set_safechars() and scols_column_get_safechars() to allow to control output encoding, safe chars are not encoded by \xFOO * modify "fromfile" test code to use build-in scols_wrapnl_* callbacks for "wrapnl" tests * add new function scols_column_get_table() Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/samples/fromfile.c')
-rw-r--r--libsmartcols/samples/fromfile.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c
index 6d4ee4aaf..fcf01c749 100644
--- a/libsmartcols/samples/fromfile.c
+++ b/libsmartcols/samples/fromfile.c
@@ -34,7 +34,7 @@ static const struct column_flag flags[] = {
{ "noextremes", SCOLS_FL_NOEXTREMES },
{ "hidden", SCOLS_FL_HIDDEN },
{ "wrap", SCOLS_FL_WRAP },
- { "wrapnl", SCOLS_FL_WRAPNL },
+ { "wrapnl", SCOLS_FL_WRAP },
{ "none", 0 }
};
@@ -101,6 +101,13 @@ static struct libscols_column *parse_column(FILE *f)
int flags = parse_column_flags(line);
if (scols_column_set_flags(cl, flags))
goto fail;
+ if (strcmp(line, "wrapnl") == 0) {
+ scols_column_set_wrapfunc(cl,
+ scols_wrapnl_chunksize,
+ scols_wrapnl_nextchunk,
+ NULL);
+ scols_column_set_safechars(cl, "\n");
+ }
break;
}
case 3: /* COLOR */