Fill table with empty rows while clearing. It will allow to get rid of clear() & refresh() each time before print the flows list.
Signed-off-by: Vadim Kochan <[email protected]> --- ui.c | 18 ++++++++++++++++++ ui.h | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ui.c b/ui.c index d5fe1a7..d8b2756 100644 --- a/ui.c +++ b/ui.c @@ -16,6 +16,7 @@ void ui_table_init(struct ui_table *tbl) tbl->rows_y = tbl->y; tbl->width = COLS; + tbl->height = LINES - 2; tbl->col_pad = 1; INIT_LIST_HEAD(&tbl->cols); @@ -93,9 +94,21 @@ void ui_table_row_add(struct ui_table *tbl) tbl->rows_y++; } +static int ui_table_width_get(struct ui_table *tbl) +{ + return tbl->width == UI_MAX_WIDTH ? COLS : tbl->width; +} + void ui_table_clear(struct ui_table *tbl) { + int max_width = ui_table_width_get(tbl); + int y; + tbl->rows_y = tbl->y; + + for (y = tbl->y + 1; y < tbl->y + tbl->height; y++) { + mvprintw(y, tbl->x, "%*s", max_width, " "); + } } #define UI_ALIGN_COL(col) (((col)->align == UI_ALIGN_LEFT) ? "%-*.*s" : "%*.*s") @@ -121,6 +134,11 @@ void ui_table_header_color_set(struct ui_table *tbl, int color) tbl->hdr_color = color; } +void ui_table_height_set(struct ui_table *tbl, int height) +{ + tbl->height = height; +} + void ui_table_header_print(struct ui_table *tbl) { struct ui_col *col; diff --git a/ui.h b/ui.h index 02d1da2..3e78472 100644 --- a/ui.h +++ b/ui.h @@ -31,12 +31,14 @@ struct ui_table { int hdr_color; int col_pad; int width; + int height; }; extern void ui_table_init(struct ui_table *tbl); extern void ui_table_uninit(struct ui_table *tbl); -extern void ui_table_pos_set(struct ui_table *tbl, int y, int x); extern void ui_table_clear(struct ui_table *tbl); +extern void ui_table_pos_set(struct ui_table *tbl, int y, int x); +extern void ui_table_height_set(struct ui_table *tbl, int height); extern void ui_table_col_add(struct ui_table *tbl, uint32_t id, char *name, uint32_t len); -- 2.6.3 -- You received this message because you are subscribed to the Google Groups "netsniff-ng" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
