summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vppinfra/format_table.c23
-rw-r--r--src/vppinfra/format_table.h19
2 files changed, 32 insertions, 10 deletions
diff --git a/src/vppinfra/format_table.c b/src/vppinfra/format_table.c
index 5d83f7a6abe..b698cfdcc56 100644
--- a/src/vppinfra/format_table.c
+++ b/src/vppinfra/format_table.c
@@ -126,17 +126,25 @@ format_table (u8 *s, va_list *args)
for (int i = 0; i < vec_len (t->row_sizes); i++)
table_width += t->row_sizes[i];
- s = format_text_cell (t, s, &title_cell, &default_title, table_width);
- s = format (s, "\n");
+ if (t->title)
+ {
+ table_text_attr_t *title_default;
+ title_default =
+ t->default_title.as_u32 ? &t->default_title : &default_title;
+ s = format_text_cell (t, s, &title_cell, title_default, table_width);
+ s = format (s, "\n");
+ }
for (int c = 0; c < vec_len (t->cells); c++)
{
table_text_attr_t *col_default;
if (c < t->n_header_cols)
- col_default = &default_header_col;
+ col_default = t->default_header_col.as_u32 ? &t->default_header_col :
+ &default_header_col;
else
- col_default = &default_body;
+ col_default =
+ t->default_body.as_u32 ? &t->default_body : &default_body;
for (int r = 0; r < vec_len (t->cells[c]); r++)
{
@@ -144,11 +152,14 @@ format_table (u8 *s, va_list *args)
if (r)
s = format (s, " ");
if (r < t->n_header_rows && c >= t->n_header_cols)
- row_default = &default_header_row;
+ row_default = t->default_header_row.as_u32 ?
+ &t->default_header_row :
+ &default_header_row;
s = format_text_cell (t, s, &t->cells[c][r], row_default,
t->row_sizes[r]);
}
- s = format (s, "\n");
+ if (c + 1 < vec_len (t->cells))
+ s = format (s, "\n");
}
return s;
diff --git a/src/vppinfra/format_table.h b/src/vppinfra/format_table.h
index f9b66a77c40..a6595333e0b 100644
--- a/src/vppinfra/format_table.h
+++ b/src/vppinfra/format_table.h
@@ -58,10 +58,17 @@ typedef enum
typedef struct
{
- table_text_attr_flags_t flags : 16;
- table_text_attr_color_t fg_color : 4;
- table_text_attr_color_t bg_color : 4;
- table_text_attr_align_t align : 4;
+ union
+ {
+ struct
+ {
+ table_text_attr_flags_t flags : 16;
+ table_text_attr_color_t fg_color : 4;
+ table_text_attr_color_t bg_color : 4;
+ table_text_attr_align_t align : 4;
+ };
+ u32 as_u32;
+ };
} table_text_attr_t;
typedef struct
@@ -79,6 +86,10 @@ typedef struct
int n_header_cols;
int n_header_rows;
int n_footer_cols;
+ table_text_attr_t default_title;
+ table_text_attr_t default_body;
+ table_text_attr_t default_header_col;
+ table_text_attr_t default_header_row;
} table_t;
__clib_export format_function_t format_table;