diff options
author | Nathan Skrzypczak <nathan.skrzypczak@gmail.com> | 2021-09-17 14:32:03 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2021-09-20 11:26:03 +0000 |
commit | 8430b8de1df1b0732beab9534a7a91fc8c7b3c7d (patch) | |
tree | 65d0d9b3c639f0b0f0c8a56215513d2ddbe7929c /src/vppinfra/format_table.c | |
parent | 41b23bc9554a134aee37b430ebf5553cc3260624 (diff) |
vppinfra: format table improvements
This adds a way to define default fg, bg colors
and alignement for cell tables.
It also allows removing the table title by not
setting it.
It also removes the trailing newline, for usage
inside a format("%U", format_table, ...)
Type: improvement
Change-Id: I27d7a04c4a919b34d0170b04e24a56831f581ea1
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/vppinfra/format_table.c')
-rw-r--r-- | src/vppinfra/format_table.c | 23 |
1 files changed, 17 insertions, 6 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; |