diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt index 071df3fff..30fb30225 100644 --- a/libsmartcols/docs/libsmartcols-sections.txt +++ b/libsmartcols/docs/libsmartcols-sections.txt @@ -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 diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index c7af6347c..269ceea0c 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -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 diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in index 2ac166b32..381a8eb9b 100644 --- a/libsmartcols/src/libsmartcols.h.in +++ b/libsmartcols/src/libsmartcols.h.in @@ -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); diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h index 8f371a7d5..163417707 100644 --- a/libsmartcols/src/smartcolsP.h +++ b/libsmartcols/src/smartcolsP.h @@ -89,8 +89,6 @@ struct libscols_column { struct libscols_cell header; struct list_head cl_columns; - - unsigned int ignore : 1; }; /* diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c index d275ad640..caae98c14 100644 --- a/libsmartcols/src/table_print.c +++ b/libsmartcols/src/table_print.c @@ -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 */ } }