Added on-line help.

This commit is contained in:
pdw
2002-10-18 13:50:07 +00:00
parent 45ccb4e4b9
commit 4e6b940b9e
4 changed files with 59 additions and 30 deletions

2
TODO
View File

@@ -1,8 +1,6 @@
Things to do for iftop Things to do for iftop
$Id$ $Id$
* Turn off services resolution.
* IP types other than v4? * IP types other than v4?
* Which average to use for the bar graph? Show several and peaks? Colours? * Which average to use for the bar graph? Show several and peaks? Colours?

View File

@@ -71,6 +71,7 @@ static void set_defaults() {
options.aggregate_src = 0; options.aggregate_src = 0;
options.aggregate_dest = 0; options.aggregate_dest = 0;
options.paused = 0; options.paused = 0;
options.showhelp = 0;
} }
static void die(char *msg) { static void die(char *msg) {

View File

@@ -42,6 +42,7 @@ typedef struct {
int aggregate_src; int aggregate_src;
int aggregate_dest; int aggregate_dest;
int paused; int paused;
int showhelp;
} options_t; } options_t;

85
ui.c
View File

@@ -24,6 +24,25 @@
#define HISTORY_DIVISIONS 3 #define HISTORY_DIVISIONS 3
#define BARGRAPH_INTERVAL 1 /* which division used for bars. */ #define BARGRAPH_INTERVAL 1 /* which division used for bars. */
#define HELP_MESSAGE \
"Host display:\n"\
" r - toggle DNS host resolution \n"\
" s - toggle show source host\n"\
" d - toggle show destination host\n"\
"\nPort display:\n"\
" R - toggle service resolution \n"\
" S - toggle show source port \n"\
" D - toggle show destination port\n"\
" p - toggle port display\n"\
"\nGeneral:\n"\
" P - pause display\n"\
" h - toggle this help display\n"\
" b - toggle bar graph display\n"\
" q - quit\n"\
"\niftop, version " IFTOP_VERSION
/* 1, 15 and 60 seconds */ /* 1, 15 and 60 seconds */
int history_divs[HISTORY_DIVISIONS] = {1, 5, 20}; int history_divs[HISTORY_DIVISIONS] = {1, 5, 20};
@@ -384,52 +403,57 @@ void ui_print() {
attron(A_REVERSE); attron(A_REVERSE);
addstr(" s "); addstr(" s ");
attroff(A_REVERSE); attroff(A_REVERSE);
addstr(options.aggregate_src ? " aggregate off " addstr(options.aggregate_src ? " show src "
: " aggregate src "); : " hide src ");
attron(A_REVERSE); attron(A_REVERSE);
addstr(" d "); addstr(" d ");
attroff(A_REVERSE); attroff(A_REVERSE);
addstr(options.aggregate_dest ? " aggregate off " addstr(options.aggregate_dest ? " show dest "
: " aggregate dest "); : " hide dest ");
draw_bar_scale(&y); draw_bar_scale(&y);
if(options.showhelp) {
mvaddstr(y,0,HELP_MESSAGE);
}
else {
/* Screen layout: we have 2 * HISTORY_DIVISIONS 6-character wide history /* Screen layout: we have 2 * HISTORY_DIVISIONS 6-character wide history
* items, and so can use COLS - 12 * HISTORY_DIVISIONS to print the two * items, and so can use COLS - 12 * HISTORY_DIVISIONS to print the two
* host names. */ * host names. */
while((nn = sorted_list_next_item(&screen_list, nn)) != NULL) { while((nn = sorted_list_next_item(&screen_list, nn)) != NULL) {
int x = 0, L; int x = 0, L;
host_pair_line* screen_line = (host_pair_line*)nn->data; host_pair_line* screen_line = (host_pair_line*)nn->data;
if(y < LINES - 4) { if(y < LINES - 4) {
L = (COLS - 8 * HISTORY_DIVISIONS - 4) / 2; L = (COLS - 8 * HISTORY_DIVISIONS - 4) / 2;
if(L > sizeof hostname) { if(L > sizeof hostname) {
L = sizeof hostname; L = sizeof hostname;
} }
sprint_host(line, &(screen_line->ap.src), screen_line->ap.src_port, screen_line->ap.protocol, L); sprint_host(line, &(screen_line->ap.src), screen_line->ap.src_port, screen_line->ap.protocol, L);
//sprintf(line, "%-*s", L, hostname); //sprintf(line, "%-*s", L, hostname);
mvaddstr(y, x, line); mvaddstr(y, x, line);
x += L; x += L;
mvaddstr(y, x, " => "); mvaddstr(y, x, " => ");
mvaddstr(y+1, x, " <= "); mvaddstr(y+1, x, " <= ");
x += 4; x += 4;
sprint_host(line, &(screen_line->ap.dst), screen_line->ap.dst_port, screen_line->ap.protocol, L); sprint_host(line, &(screen_line->ap.dst), screen_line->ap.dst_port, screen_line->ap.protocol, L);
mvaddstr(y, x, line); mvaddstr(y, x, line);
draw_line_totals(y, screen_line); draw_line_totals(y, screen_line);
} }
y += 2; y += 2;
}
} }
@@ -518,6 +542,11 @@ void ui_loop() {
tick(1); tick(1);
break; break;
case 'h':
options.showhelp = !options.showhelp;
tick(1);
break;
case 'b': case 'b':
options.showbars = !options.showbars; options.showbars = !options.showbars;
tick(1); tick(1);