ret->width_max = cl->width_max;
ret->width_avg = cl->width_avg;
ret->width_hint = cl->width_hint;
- ret->flags = cl->flags;
ret->is_extreme = cl->is_extreme;
+ ret->trunc = cl->trunc;
+ ret->tree = cl->tree;
+ ret->right = cl->right;
+ ret->strict_width = cl->strict_width;
+ ret->no_extremes = cl->no_extremes;
return ret;
err:
return cl ? cl->width_hint : -EINVAL;
}
-int scols_column_set_flags(struct libscols_column *cl, int flags)
-{
- assert(cl);
-
- if (!cl)
- return -EINVAL;
-
- cl->flags = flags;
- return 0;
-}
-
-int scols_column_get_flags(struct libscols_column *cl)
-{
- assert(cl);
- return cl ? cl->flags : -EINVAL;
-}
-
struct libscols_cell *scols_column_get_header(struct libscols_column *cl)
{
assert(cl);
return cl ? cl->color : NULL;
}
+/**
+ * scols_column_is_trunc:
+ * @cl: column
+ *
+ * Get the value of trunc
+ *
+ * Returns: trunc flag value, negative value in case of an error.
+ */
+int scols_column_is_trunc(struct libscols_column *cl)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ return cl->trunc;
+}
+/**
+ * scols_column_is_tree:
+ * @cl: column
+ *
+ * Get the value of tree
+ *
+ * Returns: tree flag value, negative value in case of an error.
+ */
+int scols_column_is_tree(struct libscols_column *cl)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ return cl->tree;
+}
+/**
+ * scols_column_is_right:
+ * @cl: column
+ *
+ * Get the value of right
+ *
+ * Returns: right flag value, negative value in case of an error.
+ */
+int scols_column_is_right(struct libscols_column *cl)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ return cl->right;
+}
+/**
+ * scols_column_is_strict_width:
+ * @cl: column
+ *
+ * Get the value of strict_width
+ *
+ * Returns: strict_width flag value, negative value in case of an error.
+ */
+int scols_column_is_strict_width(struct libscols_column *cl)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ return cl->strict_width;
+}
+/**
+ * scols_column_is_no_extremes:
+ * @cl: column
+ *
+ * Get the value of no_extremes
+ *
+ * Returns: no_extremes flag value, negative value in case of an error.
+ */
+int scols_column_is_no_extremes(struct libscols_column *cl)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ return cl->no_extremes;
+}
-
+/**
+ * scols_column_set_trunc:
+ * @cl: column
+ * @enable: 1 or 0
+ *
+ * Enable/disable trunc
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_column_set_trunc(struct libscols_column *cl, int enable)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ cl->trunc = enable;
+ return 0;
+}
+/**
+ * scols_column_set_tree:
+ * @cl: column
+ * @enable: 1 or 0
+ *
+ * Enable/disable tree
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_column_set_tree(struct libscols_column *cl, int enable)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ cl->tree = enable;
+ return 0;
+}
+/**
+ * scols_column_set_right:
+ * @cl: column
+ * @enable: 1 or 0
+ *
+ * Enable/disable right
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_column_set_right(struct libscols_column *cl, int enable)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ cl->right = enable;
+ return 0;
+}
+/**
+ * scols_column_set_strict_width:
+ * @cl: column
+ * @enable: 1 or 0
+ *
+ * Enable/disable strict_width
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_column_set_strict_width(struct libscols_column *cl, int enable)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ cl->strict_width = enable;
+ return 0;
+}
+/**
+ * scols_column_set_no_extremes:
+ * @cl: column
+ * @enable: 1 or 0
+ *
+ * Enable/disable no_extremes
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_column_set_no_extremes(struct libscols_column *cl, int enable)
+{
+ assert(cl);
+ if (!cl)
+ return -EINVAL;
+ cl->no_extremes = enable;
+ return 0;
+}
struct libscols_cell;
struct libscols_line;
struct libscols_table;
-
+struct libscols_column;
/* iter.c */
enum {
SCOLS_ITER_BACKWARD
};
-
-enum {
- /*
- * Global flags
- */
- SCOLS_FL_RAW = (1 << 1),
- SCOLS_FL_ASCII = (1 << 2),
- SCOLS_FL_NOHEADINGS = (1 << 3),
- SCOLS_FL_EXPORT = (1 << 4),
- SCOLS_FL_MAX = (1 << 5),
-
- /*
- * Column flags
- */
- SCOLS_FL_TRUNC = (1 << 15), /* truncate fields data if necessary */
- SCOLS_FL_TREE = (1 << 16), /* use tree "ascii art" */
- SCOLS_FL_RIGHT = (1 << 17), /* align to the right */
- SCOLS_FL_STRICTWIDTH = (1 << 18), /* don't reduce width if column is empty */
- SCOLS_FL_NOEXTREMES = (1 << 19), /* ignore extreme fields when count column width*/
-};
-
extern struct libscols_iter *scols_new_iter(int direction);
extern void scols_free_iter(struct libscols_iter *itr);
extern void scols_reset_iter(struct libscols_iter *itr, int direction);
extern const char *scols_cell_get_color(const struct libscols_cell *ce);
/* column.c */
+extern int scols_column_is_tree(struct libscols_column *cl);
+extern int scols_column_set_tree(struct libscols_column *cl, int enable);
+extern int scols_column_is_trunc(struct libscols_column *cl);
+extern int scols_column_set_trunc(struct libscols_column *cl, int enable);
+extern int scols_column_is_right(struct libscols_column *cl);
+extern int scols_column_set_right(struct libscols_column *cl, int enable);
+extern int scols_column_is_strict_width(struct libscols_column *cl);
+extern int scols_column_set_strict_width(struct libscols_column *cl, int enable);
+extern int scols_column_is_no_extremes(struct libscols_column *cl);
+extern int scols_column_set_no_extremes(struct libscols_column *cl, int enable);
+
extern struct libscols_column *scols_new_column(void);
extern void scols_ref_column(struct libscols_column *cl);
extern void scols_unref_column(struct libscols_column *cl);
extern struct libscols_column *scols_copy_column(const struct libscols_column *cl);
extern int scols_column_set_whint(struct libscols_column *cl, double whint);
extern double scols_column_get_whint(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);
extern struct libscols_cell *scols_column_get_header(struct libscols_column *cl);
extern int scols_column_set_color(struct libscols_column *cl, const char *color);
extern const char *scols_column_get_color(struct libscols_column *cl);
extern struct libscols_line *scols_copy_line(struct libscols_line *ln);
/* table */
-extern struct libscols_table *scols_new_table(int flags, struct libscols_symbols *syms);
+extern int scols_table_colors_wanted(struct libscols_table *tb);
+extern int scols_table_is_raw(struct libscols_table *tb);
+extern int scols_table_is_ascii(struct libscols_table *tb);
+extern int scols_table_is_no_headings(struct libscols_table *tb);
+extern int scols_table_is_export(struct libscols_table *tb);
+extern int scols_table_is_max(struct libscols_table *tb);
+extern int scols_table_is_tree(struct libscols_table *tb);
+
+extern int scols_table_enable_colors(struct libscols_table *tb, int enable);
+extern int scols_table_set_raw(struct libscols_table *tb, int enable);
+extern int scols_table_set_ascii(struct libscols_table *tb, int enable);
+extern int scols_table_set_no_headings(struct libscols_table *tb, int enable);
+extern int scols_table_set_export(struct libscols_table *tb, int enable);
+extern int scols_table_set_max(struct libscols_table *tb, int enable);
+extern int scols_table_set_tree(struct libscols_table *tb, int enable);
+
+extern struct libscols_table *scols_new_table(struct libscols_symbols *syms);
extern void scols_ref_table(struct libscols_table *tb);
extern void scols_unref_table(struct libscols_table *tb);
extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl);
extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_column *cl);
extern int scols_table_remove_columns(struct libscols_table *tb);
-extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags);
+extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint);
extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl);
extern int scols_table_get_ncols(struct libscols_table *tb);
extern int scols_table_get_nlines(struct libscols_table *tb);
-extern int scols_table_get_flags(struct libscols_table *tb);
extern struct libscols_column *scols_table_get_column(struct libscols_table *tb, size_t n);
extern int scols_table_add_line(struct libscols_table *tb, struct libscols_line *ln);
extern int scols_table_remove_line(struct libscols_table *tb, struct libscols_line *ln);
scols_cell_set_color;
scols_cell_set_data;
scols_column_get_color;
- scols_column_get_flags;
scols_column_get_header;
scols_column_get_whint;
+ scols_column_is_no_extremes;
+ scols_column_is_right;
+ scols_column_is_strict_width;
+ scols_column_is_tree;
+ scols_column_is_trunc;
scols_column_set_color;
- scols_column_set_flags;
+ scols_column_set_no_extremes;
+ scols_column_set_right;
+ scols_column_set_strict_width;
+ scols_column_set_tree;
+ scols_column_set_trunc;
scols_column_set_whint;
scols_copy_column;
scols_copy_line;
scols_symbols_set_vertical;
scols_table_add_column;
scols_table_add_line;
+ scols_table_colors_wanted;
+ scols_table_enable_colors;
scols_table_get_column;
- scols_table_get_flags;
scols_table_get_line;
scols_table_get_ncols;
scols_table_get_nlines;
scols_table_get_stream;
+ scols_table_is_ascii;
+ scols_table_is_export;
+ scols_table_is_max;
+ scols_table_is_no_headings;
+ scols_table_is_raw;
+ scols_table_is_tree;
scols_table_new_column;
scols_table_new_line;
scols_table_next_column;
scols_table_remove_columns;
scols_table_remove_line;
scols_table_remove_lines;
+ scols_table_set_ascii;
+ scols_table_set_export;
+ scols_table_set_max;
+ scols_table_set_no_headings;
+ scols_table_set_raw;
scols_table_set_stream;
scols_table_set_symbols;
+ scols_table_set_tree;
scols_unref_column;
scols_unref_line;
scols_unref_symbols;
# define assert(x)
#endif
-
/*
* Generic iterator
*/
size_t width_avg; /* average width, used to detect extreme fields */
double width_hint; /* hint (N < 1 is in percent of termwidth) */
- int flags;
int is_extreme;
char *color; /* default column color */
struct libscols_cell header;
struct list_head cl_columns;
+
+ unsigned int trunc :1; /* truncate fields data if necessary */
+ unsigned int tree :1; /* use tree "ascii art" */
+ unsigned int right :1; /* align to the right */
+ unsigned int strict_width :1; /* don't reduce width if column is empty */
+ unsigned int no_extremes :1; /* ignore extreme fields when count column width*/
};
/*
size_t termwidth; /* terminal width */
size_t termreduce; /* extra blank space */
int is_term; /* is a tty? */
- int flags;
FILE *out; /* output stream */
struct list_head tb_columns;
struct list_head tb_lines;
struct libscols_symbols *symbols;
+
+ /* flags */
+ unsigned int colors_wanted :1;
+ unsigned int raw :1;
+ unsigned int ascii :1;
+ unsigned int no_headings :1;
+ unsigned int export :1;
+ unsigned int max :1;
+ unsigned int tree :1;
};
#define IS_ITER_FORWARD(_i) ((_i)->direction == SCOLS_ITER_FORWARD)
/*
- * @flags: SCOLS_FL_* flags (usually SCOLS_FL_{ASCII,RAW})
* @syms: tree symbols or NULL for default
*
* Note that this function add a new reference to @syms
*
* Returns: newly allocated table
*/
-struct libscols_table *scols_new_table(int flags, struct libscols_symbols *syms)
+struct libscols_table *scols_new_table(struct libscols_symbols *syms)
{
struct libscols_table *tb;
if (!tb)
return NULL;
- tb->flags = flags;
tb->refcount = 1;
tb->out = stdout;
* @tb: table
* @name: column header
* @whint: column width hint (absolute width: N > 1; relative width: N < 1)
- * @flags: usually SCOLS_FL_{TREE,TRUNCATE}
*
* This is shortcut for
*
* the column header width
*
* @whint = 1..N
- * @flags = SCOLS_FL_STRICTWIDTH
- * : absolute width, empty colum won't be truncated
*
* The column is necessary to address (for example for scols_line_set_cell_data()) by
* sequential number. The first defined column has the colnum = 0. For example:
*/
struct libscols_column *scols_table_new_column(struct libscols_table *tb,
const char *name,
- double whint,
- int flags)
+ double whint)
{
struct libscols_column *cl;
struct libscols_cell *hr;
goto err;
scols_column_set_whint(cl, whint);
- scols_column_set_flags(cl, flags);
-
- if (flags & SCOLS_FL_TREE)
- tb->flags |= SCOLS_FL_TREE;
if (scols_table_add_column(tb, cl)) /* this increments column ref-counter */
goto err;
return tb ? tb->nlines : -EINVAL;
}
-/*
- * @tb: table
- *
- * Returns: flags integer
- */
-int scols_table_get_flags(struct libscols_table *tb)
-{
- assert(tb);
- return tb ? tb->flags: -EINVAL;
-}
-
int scols_table_set_stream(struct libscols_table *tb, FILE *stream)
{
assert(tb);
assert(tb);
if (!tb)
return NULL;
- ret = scols_new_table(tb->flags, tb->symbols);
+ ret = scols_new_table(tb->symbols);
if (!ret)
return NULL;
if (!tb->symbols)
return -ENOMEM;
#if defined(HAVE_WIDECHAR)
- if (!(tb->flags & SCOLS_FL_ASCII) &&
+ if (!scols_table_is_ascii(tb) &&
!strcmp(nl_langinfo(CODESET), "UTF-8")) {
scols_symbols_set_branch(tb->symbols, UTF_VR UTF_H);
scols_symbols_set_vertical(tb->symbols, UTF_V " ");
return 0;
}
+/**
+ * scols_table_enable_colors:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable colors
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_enable_colors(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ tb->colors_wanted = enable;
+ return 0;
+}
+/**
+ * scols_table_set_raw:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable raw
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_set_raw(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ tb->raw = enable;
+ return 0;
+}
+/**
+ * scols_table_set_ascii:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable ascii
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_set_ascii(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ tb->ascii = enable;
+ return 0;
+}
+/**
+ * scols_table_set_no_headings:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable no_headings
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_set_no_headings(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ tb->no_headings = enable;
+ return 0;
+}
+/**
+ * scols_table_set_export:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable export
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_set_export(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ tb->export = enable;
+ return 0;
+}
+/**
+ * scols_table_set_max:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable max
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_set_max(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ tb->max = enable;
+ return 0;
+}
+/**
+ * scols_table_set_tree:
+ * @tb: table
+ * @enable: 1 or 0
+ *
+ * Enable/disable tree
+ *
+ * Returns: 0 on success, negative number in case of an error.
+ */
+int scols_table_set_tree(struct libscols_table *tb, int enable)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ tb->tree = enable;
+ return 0;
+}
+/**
+ * scols_table_colors_wanted:
+ * @tb: table
+ *
+ * Get the value of colors_wanted
+ *
+ * Returns: colors_wanted flag value, negative value in case of an error.
+ */
+int scols_table_colors_wanted(struct libscols_table *tb)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ return tb->colors_wanted;
+}
+/**
+ * scols_table_is_raw:
+ * @tb: table
+ *
+ * Get the value of raw
+ *
+ * Returns: raw flag value, negative value in case of an error.
+ */
+int scols_table_is_raw(struct libscols_table *tb)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ return tb->raw;
+}
+/**
+ * scols_table_is_ascii:
+ * @tb: table
+ *
+ * Get the value of ascii
+ *
+ * Returns: ascii flag value, negative value in case of an error.
+ */
+int scols_table_is_ascii(struct libscols_table *tb)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ return tb->ascii;
+}
+/**
+ * scols_table_is_no_headings:
+ * @tb: table
+ *
+ * Get the value of no_headings
+ *
+ * Returns: no_headings flag value, negative value in case of an error.
+ */
+int scols_table_is_no_headings(struct libscols_table *tb)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ return tb->no_headings;
+}
+/**
+ * scols_table_is_export:
+ * @tb: table
+ *
+ * Get the value of export
+ *
+ * Returns: export flag value, negative value in case of an error.
+ */
+int scols_table_is_export(struct libscols_table *tb)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ return tb->export;
+}
+/**
+ * scols_table_is_max:
+ * @tb: table
+ *
+ * Get the value of max
+ *
+ * Returns: max flag value, negative value in case of an error.
+ */
+int scols_table_is_max(struct libscols_table *tb)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ return tb->max;
+}
+/**
+ * scols_table_is_tree:
+ * @tb: table
+ *
+ * Get the value of tree
+ *
+ * Returns: tree flag value, negative value in case of an error.
+ */
+int scols_table_is_tree(struct libscols_table *tb)
+{
+ assert(tb);
+ if (!tb)
+ return -EINVAL;
+ return tb->tree;
+}
data = "";
/* raw mode */
- if (tb->flags & SCOLS_FL_RAW) {
+ if (scols_table_is_raw(tb)) {
fputs_nonblank(data, tb->out);
if (!is_last_column(tb, cl))
fputc(' ', tb->out);
}
/* NAME=value mode */
- if (tb->flags & SCOLS_FL_EXPORT) {
+ if (scols_table_is_export(tb)) {
fprintf(tb->out, "%s=", scols_cell_get_data(&cl->header));
fputs_quoted(data, tb->out);
if (!is_last_column(tb, cl))
return;
}
- if (tb->is_term) {
+ if (tb->colors_wanted) {
if (ce && !color)
color = ce->color;
if (ln && !color)
}
width = cl->width;
- if (is_last_column(tb, cl) && len < width && !(tb->flags & SCOLS_FL_MAX))
+ if (is_last_column(tb, cl) && len < width && !scols_table_is_max(tb))
width = len;
/* truncate data */
- if (len > width && (cl->flags & SCOLS_FL_TRUNC)) {
+ if (len > width && scols_column_is_trunc(cl)) {
if (data)
len = mbs_truncate(data, &width);
if (!data || len == (size_t) -1) {
}
}
if (data) {
- if (!(tb->flags & SCOLS_FL_RAW) && (cl->flags & SCOLS_FL_RIGHT)) {
+ if (!scols_table_is_raw(tb) && scols_column_is_right(cl)) {
size_t xw = cl->width;
if (color)
fputs(color, tb->out);
fputc(' ', tb->out); /* padding */
if (!is_last_column(tb, cl)) {
- if (len > width && !(cl->flags & SCOLS_FL_TRUNC)) {
+ if (len > width && !scols_column_is_trunc(cl)) {
fputc('\n', tb->out);
for (i = 0; i <= (size_t) cl->seqnum; i++) {
struct libscols_column *x = scols_table_get_column(tb, i);
if (!data)
return NULL;
- if (!(cl->flags & SCOLS_FL_TREE)) {
+ if (!scols_column_is_tree(cl)) {
strncpy(buf, data, bufsz);
buf[bufsz - 1] = '\0';
return buf;
assert(tb);
- if ((tb->flags & SCOLS_FL_NOHEADINGS) ||
- (tb->flags & SCOLS_FL_EXPORT) ||
+ if (scols_table_is_no_headings(tb) ||
+ scols_table_is_export(tb) ||
list_empty(&tb->tb_lines))
return;
if (cl->is_extreme && len > cl->width_avg * 2)
continue;
- else if (cl->flags & SCOLS_FL_NOEXTREMES) {
+ else if (scols_column_is_no_extremes(cl)) {
sum += len;
count++;
}
cl->width_min = mbs_safe_width(scols_cell_get_data(&cl->header));
/* enlarge to minimal width */
- if (cl->width < cl->width_min && !(cl->flags & SCOLS_FL_STRICTWIDTH))
+ if (cl->width < cl->width_min && !scols_column_is_strict_width(cl))
cl->width = cl->width_min;
/* use relative size for large columns */
}
}
- if (width < tb->termwidth && (tb->flags & SCOLS_FL_MAX)) {
+ if (width < tb->termwidth && scols_table_is_max(tb)) {
/* try enlarge all columns */
while (width < tb->termwidth) {
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
struct libscols_column *cl = list_entry(
tb->tb_columns.prev, struct libscols_column, cl_columns);
- if (!(cl->flags & SCOLS_FL_RIGHT) && tb->termwidth - width > 0) {
+ if (!scols_column_is_right(cl) && tb->termwidth - width > 0) {
cl->width += tb->termwidth - width;
width = tb->termwidth;
}
while (scols_table_next_column(tb, &itr, &cl) == 0) {
if (width <= tb->termwidth)
break;
- if (cl->width_hint > 1 && !(cl->flags & SCOLS_FL_TRUNC))
+ if (cl->width_hint > 1 && !scols_column_is_trunc(cl))
continue; /* never truncate columns with absolute sizes */
- if (cl->flags & SCOLS_FL_TREE)
+ if (scols_column_is_tree(cl))
continue; /* never truncate the tree */
- if (trunc_only && !(cl->flags & SCOLS_FL_TRUNC))
+ if (trunc_only && !scols_column_is_trunc(cl))
continue;
if (cl->width == cl->width_min)
continue;
if (!line)
return -ENOMEM;
- if (!((tb->flags & SCOLS_FL_RAW) || (tb->flags & SCOLS_FL_EXPORT)))
+ if (!(scols_table_is_raw(tb) || scols_table_is_export(tb)))
recount_widths(tb, line, line_sz);
- if (tb->flags & SCOLS_FL_TREE)
+ if (scols_table_is_tree(tb))
print_tree(tb, line, line_sz);
else
print_table(tb, line, line_sz);
{
struct libscols_table *tb;
struct libscols_column *cl;
- int flags = 0, notree = 0, clone = 0, i, color = 0;
+ int notree = 0, clone = 0, i, color = 0;
+
+ tb = scols_new_table(NULL);
+ if (!tb)
+ err(EXIT_FAILURE, "table initialization failed");
if (argc == 2 && !strcmp(argv[1], "--help")) {
printf("%s [--max | --ascii | --raw | --export | --list | "
"--color | --colortree | --clone | --clonetree]\n",
program_invocation_short_name);
+ scols_unref_table(tb);
return EXIT_SUCCESS;
} else if (argc == 2 && !strcmp(argv[1], "--max")) {
- flags |= SCOLS_FL_MAX;
+ scols_table_set_max(tb, 1);
} else if (argc == 2 && !strcmp(argv[1], "--ascii")) {
- flags |= SCOLS_FL_ASCII;
+ scols_table_set_ascii(tb, 1);
} else if (argc == 2 && !strcmp(argv[1], "--raw")) {
- flags |= SCOLS_FL_RAW;
+ scols_table_set_raw(tb, 1);
notree = 1;
} else if (argc == 2 && !strcmp(argv[1], "--export")) {
- flags |= SCOLS_FL_EXPORT;
+ scols_table_set_export(tb, 1);
notree = 1;
} else if (argc == 2 && !strcmp(argv[1], "--list")) {
notree = 1;
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- tb = scols_new_table(flags, NULL);
- if (!tb)
- err(EXIT_FAILURE, "table initialization failed");
+ cl = scols_table_new_column(tb, "NAME", 0.3);
+ scols_table_set_tree(tb, !notree);
+ scols_table_enable_colors(tb, color);
- cl = scols_table_new_column(tb, "NAME", 0.3, notree ? 0 : SCOLS_FL_TREE);
if (color)
scols_column_set_color(cl, UL_COLOR_RED);
- cl = scols_table_new_column(tb, "FOO", 0.3, SCOLS_FL_TRUNC);
+ cl = scols_table_new_column(tb, "FOO", 0.3);
+ scols_column_set_trunc(cl, 1);
if (color) {
struct libscols_cell *h = scols_column_get_header(cl);
scols_column_set_color(cl, UL_COLOR_BOLD_GREEN);
scols_cell_set_color(h, UL_COLOR_GREEN);
}
- scols_table_new_column(tb, "BAR", 0.3, 0);
- scols_table_new_column(tb, "PATH", 0.3, 0);
+ scols_table_new_column(tb, "BAR", 0.3);
+ scols_table_new_column(tb, "PATH", 0.3);
for (i = 0; i < 2; i++) {
struct libscols_line *ln = scols_table_new_line(tb, NULL);