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);
assert(cl);
if (!cl)
return -EINVAL;
- return cl->trunc;
+ return cl->flags & SCOLS_FL_TRUNC;
}
/**
* scols_column_is_tree:
assert(cl);
if (!cl)
return -EINVAL;
- return cl->tree;
+ return cl->flags & SCOLS_FL_TREE;
}
/**
* scols_column_is_right:
assert(cl);
if (!cl)
return -EINVAL;
- return cl->right;
+ return cl->flags & SCOLS_FL_RIGHT;
}
/**
* scols_column_is_strict_width:
assert(cl);
if (!cl)
return -EINVAL;
- return cl->strict_width;
+ return cl->flags & SCOLS_FL_STRICTWIDTH;
}
/**
* scols_column_is_no_extremes:
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;
+ return cl->flags & SCOLS_FL_NOEXTREMES;
}
SCOLS_ITER_BACKWARD
};
+enum {
+ /*
+ * 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);
/* 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 int scols_column_set_flags(struct libscols_column *cl, int flags);
+extern int scols_column_get_flags(struct libscols_column *cl);
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 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);
+extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags);
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);
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_tree;
scols_column_is_trunc;
scols_column_set_color;
- 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_flags;
scols_column_set_whint;
scols_copy_column;
scols_copy_line;
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*/
};
/*
*/
struct libscols_column *scols_table_new_column(struct libscols_table *tb,
const char *name,
- double whint)
+ double whint,
+ int flags)
{
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)
+ scols_table_set_tree(tb, 1);
if (scols_table_add_column(tb, cl)) /* this increments column ref-counter */
goto err;
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- cl = scols_table_new_column(tb, "NAME", 0.3);
- scols_table_set_tree(tb, !notree);
+ cl = scols_table_new_column(tb, "NAME", 0.3, notree ? 0 : SCOLS_FL_TREE);
scols_table_enable_colors(tb, color);
if (color)
scols_column_set_color(cl, UL_COLOR_RED);
- cl = scols_table_new_column(tb, "FOO", 0.3);
- scols_column_set_trunc(cl, 1);
+ cl = scols_table_new_column(tb, "FOO", 0.3, SCOLS_FL_TRUNC);
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, "green"); /* a human-readable string is also legal */
}
- scols_table_new_column(tb, "BAR", 0.3);
- scols_table_new_column(tb, "PATH", 0.3);
+ scols_table_new_column(tb, "BAR", 0.3, 0);
+ scols_table_new_column(tb, "PATH", 0.3, 0);
for (i = 0; i < 2; i++) {
struct libscols_line *ln = scols_table_new_line(tb, NULL);
scols_line_set_data(ln, MYCOL_FOO, "a.b-foo-foo");
scols_line_set_data(ln, MYCOL_BAR, "barBar-A.B");
scols_line_set_data(ln, MYCOL_PATH, "/mnt/AAA/B");
+
if (color)
scols_cell_set_color(scols_line_get_cell(ln, MYCOL_FOO),
UL_COLOR_MAGENTA);