summaryrefslogtreecommitdiffstats
path: root/libsmartcols/samples
diff options
context:
space:
mode:
authorKarel Zak2016-09-06 13:01:45 +0200
committerKarel Zak2016-09-06 13:01:45 +0200
commita2b8ad291f599230c72886a811d455531402458f (patch)
treeb9e6b79c293d51cca314bafc70b45041b7cd0eac /libsmartcols/samples
parentlibsmartcols: fix padding for non-maxout output (diff)
downloadkernel-qcow2-util-linux-a2b8ad291f599230c72886a811d455531402458f.tar.gz
kernel-qcow2-util-linux-a2b8ad291f599230c72886a811d455531402458f.tar.xz
kernel-qcow2-util-linux-a2b8ad291f599230c72886a811d455531402458f.zip
libsmartcols: extend wrapnl sample
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/samples')
-rw-r--r--libsmartcols/samples/wrapnl.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/libsmartcols/samples/wrapnl.c b/libsmartcols/samples/wrapnl.c
index 6de9e08a6..01fd2edff 100644
--- a/libsmartcols/samples/wrapnl.c
+++ b/libsmartcols/samples/wrapnl.c
@@ -23,17 +23,19 @@
static int opt_random;
-enum { COL_NAME, COL_DATA, COL_LIKE };
+enum { COL_NAME, COL_DATA1, COL_LIKE, COL_DATA2 };
/* add columns to the @tb */
static void setup_columns(struct libscols_table *tb)
{
if (!scols_table_new_column(tb, "NAME", 0, SCOLS_FL_TREE))
goto fail;
- if (!scols_table_new_column(tb, "DATA", 0, SCOLS_FL_WRAPNL))
+ if (!scols_table_new_column(tb, "DATA1", 0, SCOLS_FL_WRAPNL))
goto fail;
if (!scols_table_new_column(tb, "LIKE", 0, SCOLS_FL_RIGHT))
goto fail;
+ if (!scols_table_new_column(tb, "DATA2", 0, SCOLS_FL_WRAPNL))
+ goto fail;
return;
fail:
scols_unref_table(tb);
@@ -72,11 +74,12 @@ static struct libscols_line * add_line( struct libscols_table *tb,
if (scols_line_set_data(ln, COL_NAME, gen_text(prefix, "N", buf, 15, 0)))
goto fail;
- if (scols_line_set_data(ln, COL_DATA, gen_text(prefix, "F", buf, 40, 1)))
+ if (scols_line_set_data(ln, COL_DATA1, gen_text(prefix, "D", buf, 40, 1)))
goto fail;
if (scols_line_set_data(ln, COL_LIKE, "1"))
goto fail;
-
+ if (scols_line_set_data(ln, COL_DATA2, gen_text(prefix, "E", buf, 40, 1)))
+ goto fail;
return ln;
fail:
scols_unref_table(tb);
@@ -90,17 +93,27 @@ int main(int argc, char *argv[])
int c;
static const struct option longopts[] = {
- { "random", 0, 0, 'r' },
+ { "random", 0, 0, 'r' },
+ { "maxout", 0, 0, 'm' },
{ NULL, 0, 0, 0 },
};
setlocale(LC_ALL, ""); /* just to have enable UTF8 chars */
- while((c = getopt_long(argc, argv, "r", longopts, NULL)) != -1) {
+ scols_init_debug(0);
+
+ tb = scols_new_table();
+ if (!tb)
+ err(EXIT_FAILURE, "failed to create output table");
+
+ while((c = getopt_long(argc, argv, "rm", longopts, NULL)) != -1) {
switch(c) {
case 'r':
opt_random = 1;
break;
+ case 'm':
+ scols_table_enable_maxout(tb, TRUE);
+ break;
default:
err(EXIT_FAILURE, "%s [-r|--random]\n", program_invocation_short_name);
}
@@ -109,12 +122,6 @@ int main(int argc, char *argv[])
if (opt_random)
xsrand();
- scols_init_debug(0);
-
- tb = scols_new_table();
- if (!tb)
- err(EXIT_FAILURE, "failed to create output table");
-
scols_table_enable_colors(tb, isatty(STDOUT_FILENO));
setup_columns(tb);