summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-08-23 00:06:02 +0300
committerTobias Klauser <tklauser@distanz.ch>2016-09-15 18:28:28 +0200
commite18c0f2a23fc9e62a5be13af270cb81326ee6550 (patch)
treebdb0b5a95033c98985e9c3ca9f26fd8a9b6ab4f5
parentca4cd5bec239b88b72fccb2f4849e634a504b260 (diff)
flowtop: Add horizontal scrolling over flows table
Add left/right scrolling for flows list table to make possible see all the columns with a smaller display size. Handle 'Left' & 'Right' keypress to scroll left or right. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--flowtop.c32
-rw-r--r--ui.c25
-rw-r--r--ui.h8
3 files changed, 46 insertions, 19 deletions
diff --git a/flowtop.c b/flowtop.c
index d98a7b6..1052e08 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -1190,22 +1190,24 @@ static void draw_help(void)
mvaddnstr(row + 4, col + 3, "Up, u, k Move up", -1);
mvaddnstr(row + 5, col + 3, "Down, d, j Move down", -1);
- mvaddnstr(row + 6, col + 3, "? Toggle help window", -1);
- mvaddnstr(row + 7, col + 3, "q, Ctrl+C Quit", -1);
+ mvaddnstr(row + 6, col + 3, "Left,l Scroll left", -1);
+ mvaddnstr(row + 7, col + 3, "Right,h Scroll right", -1);
+ mvaddnstr(row + 8, col + 3, "? Toggle help window", -1);
+ mvaddnstr(row + 9, col + 3, "q, Ctrl+C Quit", -1);
attron(A_BOLD | A_UNDERLINE);
- mvaddnstr(row + 9, col + 2, "Display Settings", -1);
+ mvaddnstr(row + 11, col + 2, "Display Settings", -1);
attroff(A_BOLD | A_UNDERLINE);
- mvaddnstr(row + 11, col + 3, "b Toggle rate units (bits/bytes)", -1);
- mvaddnstr(row + 12, col + 3, "a Toggle display of active flows (rate > 0) only", -1);
- mvaddnstr(row + 13, col + 3, "s Toggle show source peer info", -1);
+ mvaddnstr(row + 13, col + 3, "b Toggle rate units (bits/bytes)", -1);
+ mvaddnstr(row + 14, col + 3, "a Toggle display of active flows (rate > 0) only", -1);
+ mvaddnstr(row + 15, col + 3, "s Toggle show source peer info", -1);
- mvaddnstr(row + 15, col + 3, "T Toggle display TCP flows", -1);
- mvaddnstr(row + 16, col + 3, "U Toggle display UDP flows", -1);
- mvaddnstr(row + 17, col + 3, "D Toggle display DCCP flows", -1);
- mvaddnstr(row + 18, col + 3, "I Toggle display ICMP flows", -1);
- mvaddnstr(row + 19, col + 3, "S Toggle display SCTP flows", -1);
+ mvaddnstr(row + 17, col + 3, "T Toggle display TCP flows", -1);
+ mvaddnstr(row + 18, col + 3, "U Toggle display UDP flows", -1);
+ mvaddnstr(row + 19, col + 3, "D Toggle display DCCP flows", -1);
+ mvaddnstr(row + 20, col + 3, "I Toggle display ICMP flows", -1);
+ mvaddnstr(row + 21, col + 3, "S Toggle display SCTP flows", -1);
}
static void draw_header(WINDOW *screen)
@@ -1332,6 +1334,14 @@ static void presenter(void)
if (skip_lines > SCROLL_MAX)
skip_lines = SCROLL_MAX;
break;
+ case KEY_LEFT:
+ case 'h':
+ ui_table_event_send(&flows_tbl, UI_EVT_SCROLL_LEFT);
+ break;
+ case KEY_RIGHT:
+ case 'l':
+ ui_table_event_send(&flows_tbl, UI_EVT_SCROLL_RIGHT);
+ break;
case 'b':
if (rate_type == RATE_BYTES)
rate_type = RATE_BITS;
diff --git a/ui.c b/ui.c
index 23a2293..1ab56af 100644
--- a/ui.c
+++ b/ui.c
@@ -154,7 +154,7 @@ void ui_table_clear(struct ui_table *tbl)
void ui_table_row_show(struct ui_table *tbl)
{
- mvaddchstr(tbl->rows_y, tbl->x, tbl->row->str);
+ mvaddchstr(tbl->rows_y, tbl->x, tbl->row->str + tbl->scroll_x);
ui_text_len_set(tbl->row, 0);
}
@@ -190,19 +190,28 @@ void ui_table_height_set(struct ui_table *tbl, int height)
void ui_table_header_print(struct ui_table *tbl)
{
struct ui_col *col;
- int max_width = tbl->width;
- int width = 0;
+
+ attron(tbl->hdr_color);
+ mvprintw(tbl->y, tbl->x, "%*s", tbl->width, " ");
+ attroff(tbl->hdr_color);
list_for_each_entry(col, &tbl->cols, entry) {
__ui_table_row_print(tbl, col, tbl->hdr_color, col->name);
- if (width + col->len + tbl->col_pad < max_width)
- width += col->len + tbl->col_pad;
}
ui_table_row_show(tbl);
+}
- attron(tbl->hdr_color);
- mvprintw(tbl->y, width, "%*s", max_width - width, " ");
- attroff(tbl->hdr_color);
+#define SCROLL_X_STEP 10
+
+void ui_table_event_send(struct ui_table *tbl, enum ui_event_id evt_id)
+{
+ if (evt_id == UI_EVT_SCROLL_RIGHT) {
+ tbl->scroll_x += SCROLL_X_STEP;
+ } else if (evt_id == UI_EVT_SCROLL_LEFT) {
+ tbl->scroll_x -= SCROLL_X_STEP;
+ if (tbl->scroll_x < 0)
+ tbl->scroll_x = 0;
+ }
}
diff --git a/ui.h b/ui.h
index 7f4814c..65338d1 100644
--- a/ui.h
+++ b/ui.h
@@ -6,6 +6,11 @@
#include "list.h"
+enum ui_event_id {
+ UI_EVT_SCROLL_LEFT,
+ UI_EVT_SCROLL_RIGHT,
+};
+
enum ui_align {
UI_ALIGN_LEFT,
UI_ALIGN_RIGHT,
@@ -37,6 +42,7 @@ struct ui_table {
int col_pad;
int width;
int height;
+ int scroll_x;
};
extern void ui_table_init(struct ui_table *tbl);
@@ -58,4 +64,6 @@ extern void ui_table_row_print(struct ui_table *tbl, uint32_t col_id,
extern void ui_table_header_color_set(struct ui_table *tbl, int color);
extern void ui_table_header_print(struct ui_table *tbl);
+extern void ui_table_event_send(struct ui_table *tbl, enum ui_event_id id);
+
#endif /* UI_H */