]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - libsmartcols/samples/title.c
ec72093cc952286cabc1ffbde9ac10825ede6418
2 * Copyright (C) 2010-2014 Karel Zak <kzak@redhat.com>
4 * This file may be redistributed under the terms of the
5 * GNU Lesser General Public License.
11 #include <sys/types.h>
21 #include "libsmartcols.h"
24 enum { COL_NAME
, COL_DATA
};
26 /* add columns to the @tb */
27 static void setup_columns(struct libscols_table
*tb
)
29 if (!scols_table_new_column(tb
, "NAME", 0, 0))
31 if (!scols_table_new_column(tb
, "DATA", 0, 0))
35 scols_unref_table(tb
);
36 err(EXIT_FAILURE
, "faild to create output columns");
39 static void add_line(struct libscols_table
*tb
, const char *name
, const char *data
)
41 struct libscols_line
*ln
= scols_table_new_line(tb
, NULL
);
43 err(EXIT_FAILURE
, "failed to create output line");
45 if (scols_line_set_data(ln
, COL_NAME
, name
))
47 if (scols_line_set_data(ln
, COL_DATA
, data
))
51 scols_unref_table(tb
);
52 err(EXIT_FAILURE
, "faild to create output line");
55 int main(int argc
, char *argv
[])
57 struct libscols_table
*tb
;
58 struct libscols_symbols
*sy
;
59 struct libscols_cell
*title
;
61 setlocale(LC_ALL
, ""); /* just to have enable UTF8 chars */
65 tb
= scols_new_table();
67 err(EXIT_FAILURE
, "faild to create output table");
69 scols_table_enable_colors(tb
, 1);
71 add_line(tb
, "foo", "bla bla bla");
72 add_line(tb
, "bar", "alb alb alb");
74 title
= scols_table_get_title(tb
);
77 scols_cell_set_data(title
, "This is right title");
78 scols_cell_set_color(title
, "red");
79 scols_cell_set_flags(title
, SCOLS_CELL_FL_RIGHT
);
80 scols_print_table(tb
);
83 sy
= scols_new_symbols();
86 scols_table_set_symbols(tb
, sy
);
88 scols_symbols_set_title_padding(sy
, "=");
89 scols_cell_set_data(title
, "This is center title (with padding)");
90 scols_cell_set_color(title
, "green");
91 scols_cell_set_flags(title
, SCOLS_CELL_FL_CENTER
);
92 scols_print_table(tb
);
95 scols_symbols_set_title_padding(sy
, "-");
96 scols_cell_set_data(title
, "This is left title (with padding)");
97 scols_cell_set_color(title
, "blue");
98 scols_cell_set_flags(title
, SCOLS_CELL_FL_LEFT
);
99 scols_print_table(tb
);
101 scols_unref_table(tb
);