summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOndrej Oprala2014-03-24 16:44:33 +0100
committerKarel Zak2014-04-03 12:29:17 +0200
commit8b992cb5719e7632dd8bc904cb5bfb3720207739 (patch)
tree00d81f77373bdeac1394dec7a3f8dabbbf9cf923
parentlibsmartcols: colors may now be specified as human-readable strings (diff)
downloadkernel-qcow2-util-linux-8b992cb5719e7632dd8bc904cb5bfb3720207739.tar.gz
kernel-qcow2-util-linux-8b992cb5719e7632dd8bc904cb5bfb3720207739.tar.xz
kernel-qcow2-util-linux-8b992cb5719e7632dd8bc904cb5bfb3720207739.zip
libsmartcols: revert the column flags API
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
-rw-r--r--libsmartcols/src/column.c119
-rw-r--r--libsmartcols/src/libsmartcols.h.in20
-rw-r--r--libsmartcols/src/libsmartcols.sym7
-rw-r--r--libsmartcols/src/smartcolsP.h7
-rw-r--r--libsmartcols/src/table.c7
-rw-r--r--libsmartcols/src/test.c11
6 files changed, 51 insertions, 120 deletions
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c
index 29eb63666..8e9b11fdd 100644
--- a/libsmartcols/src/column.c
+++ b/libsmartcols/src/column.c
@@ -66,12 +66,8 @@ struct libscols_column *scols_copy_column(const struct libscols_column *cl)
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:
@@ -96,6 +92,23 @@ double scols_column_get_whint(struct libscols_column *cl)
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);
@@ -154,7 +167,7 @@ int scols_column_is_trunc(struct libscols_column *cl)
assert(cl);
if (!cl)
return -EINVAL;
- return cl->trunc;
+ return cl->flags & SCOLS_FL_TRUNC;
}
/**
* scols_column_is_tree:
@@ -169,7 +182,7 @@ int scols_column_is_tree(struct libscols_column *cl)
assert(cl);
if (!cl)
return -EINVAL;
- return cl->tree;
+ return cl->flags & SCOLS_FL_TREE;
}
/**
* scols_column_is_right:
@@ -184,7 +197,7 @@ int scols_column_is_right(struct libscols_column *cl)
assert(cl);
if (!cl)
return -EINVAL;
- return cl->right;
+ return cl->flags & SCOLS_FL_RIGHT;
}
/**
* scols_column_is_strict_width:
@@ -199,7 +212,7 @@ int scols_column_is_strict_width(struct libscols_column *cl)
assert(cl);
if (!cl)
return -EINVAL;
- return cl->strict_width;
+ return cl->flags & SCOLS_FL_STRICTWIDTH;
}
/**
* scols_column_is_no_extremes:
@@ -214,91 +227,5 @@ 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;
+ return cl->flags & SCOLS_FL_NOEXTREMES;
}
diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in
index 412c8cd09..54a623c43 100644
--- a/libsmartcols/src/libsmartcols.h.in
+++ b/libsmartcols/src/libsmartcols.h.in
@@ -33,6 +33,17 @@ enum {
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);
@@ -59,16 +70,13 @@ 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 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);
@@ -124,7 +132,7 @@ 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);
+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);
diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym
index b6538a5bc..90ecd771c 100644
--- a/libsmartcols/src/libsmartcols.sym
+++ b/libsmartcols/src/libsmartcols.sym
@@ -10,6 +10,7 @@ global:
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;
@@ -18,11 +19,7 @@ global:
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;
diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h
index be2b0cfbf..18ca22a14 100644
--- a/libsmartcols/src/smartcolsP.h
+++ b/libsmartcols/src/smartcolsP.h
@@ -67,17 +67,12 @@ struct libscols_column {
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*/
};
/*
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c
index cb48ce4cb..bbbd5a59d 100644
--- a/libsmartcols/src/table.c
+++ b/libsmartcols/src/table.c
@@ -159,7 +159,8 @@ int scols_table_remove_columns(struct libscols_table *tb)
*/
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;
@@ -179,6 +180,10 @@ struct libscols_column *scols_table_new_column(struct libscols_table *tb,
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;
diff --git a/libsmartcols/src/test.c b/libsmartcols/src/test.c
index 0899cea31..aee4d8855 100644
--- a/libsmartcols/src/test.c
+++ b/libsmartcols/src/test.c
@@ -76,23 +76,21 @@ int main(int argc, char *argv[])
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);
@@ -122,6 +120,7 @@ int main(int argc, char *argv[])
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);