libsmartcols: add SCOLS_FL_HIDDEN

Export "don't print this column" functionality by public API.

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2015-12-10 13:02:03 +01:00
parent 0f1cbe9430
commit 6d6b6d185e
5 changed files with 23 additions and 7 deletions

View File

@ -20,6 +20,7 @@ scols_column_get_color
scols_column_get_flags
scols_column_get_header
scols_column_get_whint
scols_column_is_hidden
scols_column_is_noextremes
scols_column_is_right
scols_column_is_strict_width

View File

@ -258,6 +258,21 @@ int scols_column_set_cmpfunc(struct libscols_column *cl,
return 0;
}
/**
* scols_column_is_hidden:
* @cl: a pointer to a struct libscols_column instance
*
* Gets the value of @cl's flag hidden.
*
* Returns: hidden flag value, negative value in case of an error.
*/
int scols_column_is_hidden(struct libscols_column *cl)
{
if (!cl)
return -EINVAL;
return cl->flags & SCOLS_FL_HIDDEN;
}
/**
* scols_column_is_trunc:
* @cl: a pointer to a struct libscols_column instance

View File

@ -83,6 +83,7 @@ enum {
SCOLS_FL_RIGHT = (1 << 2), /* align to the right */
SCOLS_FL_STRICTWIDTH = (1 << 3), /* don't reduce width if column is empty */
SCOLS_FL_NOEXTREMES = (1 << 4), /* ignore extreme fields when count column width*/
SCOLS_FL_HIDDEN = (1 << 5), /* maintain data, but don't print */
};
extern struct libscols_iter *scols_new_iter(int direction);
@ -126,6 +127,7 @@ extern int scols_column_is_tree(struct libscols_column *cl);
extern int scols_column_is_trunc(struct libscols_column *cl);
extern int scols_column_is_right(struct libscols_column *cl);
extern int scols_column_is_strict_width(struct libscols_column *cl);
extern int scols_column_is_hidden(struct libscols_column *cl);
extern int scols_column_is_noextremes(struct libscols_column *cl);
extern int scols_column_set_flags(struct libscols_column *cl, int flags);

View File

@ -89,8 +89,6 @@ struct libscols_column {
struct libscols_cell header;
struct list_head cl_columns;
unsigned int ignore : 1;
};
/*

View File

@ -185,7 +185,7 @@ static int is_last_column(struct libscols_table *tb, struct libscols_column *cl)
return 1;
next = list_entry(cl->cl_columns.next, struct libscols_column, cl_columns);
if (next && next->ignore)
if (next && scols_column_is_hidden(next))
return 1;
return 0;
}
@ -532,7 +532,7 @@ static int print_line(struct libscols_table *tb,
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) {
if (cl->ignore)
if (scols_column_is_hidden(cl))
continue;
rc = cell_to_buffer(tb, ln, cl, buf);
if (!rc)
@ -563,7 +563,7 @@ static int print_header(struct libscols_table *tb, struct libscols_buffer *buf)
/* set the width according to the size of the data */
scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) {
if (cl->ignore)
if (scols_column_is_hidden(cl))
continue;
rc = buffer_set_data(buf, scols_cell_get_data(&cl->header));
if (!rc)
@ -660,7 +660,7 @@ static int print_tree(struct libscols_table *tb, struct libscols_buffer *buf)
static void dbg_column(struct libscols_table *tb, struct libscols_column *cl)
{
if (cl->ignore) {
if (scols_column_is_hidden(cl)) {
DBG(COL, ul_debugobj(cl, "%s ignored", cl->header.data));
return;
}
@ -949,7 +949,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
cl->width -= r;
width -= r;
} else {
cl->ignore = 1;
cl->flags |= SCOLS_FL_HIDDEN;
width -= cl->width + 1; /* +1 means separator between columns */
}
}