From e130318d8a1a12fd30cb430d8df1e4ffa274c83a Mon Sep 17 00:00:00 2001 From: Denis Afonin Date: Sat, 3 Aug 2024 19:16:57 +0300 Subject: [PATCH 1/2] Add a compact mode in curses --- ui/curses.c | 63 ++++++++++++++++++++++++++++++---------------------- ui/display.h | 2 +- ui/mtr.h | 2 +- ui/select.c | 4 ++++ 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/ui/curses.c b/ui/curses.c index d01e178c..3b295f22 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -172,6 +172,8 @@ int mtr_curses_keyaction( return ActionReset; case 'd': return ActionDisplay; + case 'c': + return ActionCompact; case 'e': return ActionMPLS; case 'n': @@ -345,6 +347,7 @@ int mtr_curses_keyaction( printw(" ?|h help\n"); printw(" p pause (SPACE to resume)\n"); printw(" d switching display mode\n"); + printw(" c switching compact mode\n"); printw(" e toggle MPLS information on/off\n"); printw(" n toggle DNS on/off\n"); printw(" r reset all counters\n"); @@ -689,7 +692,7 @@ void mtr_curses_redraw( erase(); getmaxyx(stdscr, __unused_int, maxx); - rowstat = 5; + rowstat = !ctl->CompactLayout; move(0, 0); attron(A_BOLD); @@ -698,34 +701,38 @@ void mtr_curses_redraw( pwcenter(buf); attroff(A_BOLD); - mvprintw(1, 0, "%s (%s) -> %s (%s)", + mvprintw(rowstat, 0, "%s (%s) -> %s (%s)", ctl->LocalHostname, net_localaddr(), ctl->Hostname, net_remoteaddr()); t = time(NULL); - mvprintw(1, maxx - 25, "%s", iso_time(&t)); - printw("\n"); + mvprintw(rowstat, maxx - 25, "%s", iso_time(&t)); + if (rowstat) { + printw("\n"); - printw("Keys: "); - attron(A_BOLD); - printw("H"); - attroff(A_BOLD); - printw("elp "); - attron(A_BOLD); - printw("D"); - attroff(A_BOLD); - printw("isplay mode "); - attron(A_BOLD); - printw("R"); - attroff(A_BOLD); - printw("estart statistics "); - attron(A_BOLD); - printw("O"); - attroff(A_BOLD); - printw("rder of fields "); - attron(A_BOLD); - printw("q"); - attroff(A_BOLD); - printw("uit\n"); + printw("Keys: "); + attron(A_BOLD); + printw("H"); + attroff(A_BOLD); + printw("elp "); + attron(A_BOLD); + printw("D"); + attroff(A_BOLD); + printw("isplay mode "); + attron(A_BOLD); + printw("R"); + attroff(A_BOLD); + printw("estart statistics "); + attron(A_BOLD); + printw("O"); + attroff(A_BOLD); + printw("rder of fields "); + attron(A_BOLD); + printw("q"); + attroff(A_BOLD); + printw("uit\n"); + } + + rowstat = rowstat ? 5 : 1; if (ctl->display_mode == DisplayModeDefault) { for (i = 0; i < MAXFLD; i++) { @@ -761,8 +768,10 @@ void mtr_curses_redraw( maxx <= SAVED_PINGS + padding ? maxx - padding : SAVED_PINGS; startstat = padding - 2; - snprintf(msg, sizeof(msg), " Last %3d pings", max_cols); - mvprintw(rowstat - 1, startstat, "%s", msg); + if (rowstat > 1) { + snprintf(msg, sizeof(msg), " Last %3d pings", max_cols); + mvprintw(rowstat - 1, startstat, "%s", msg); + } attroff(A_BOLD); move(rowstat, 0); diff --git a/ui/display.h b/ui/display.h index 0c16e90c..b4eca77c 100644 --- a/ui/display.h +++ b/ui/display.h @@ -20,7 +20,7 @@ /* Don't put a trailing comma in enumeration lists. Some compilers (notably the one on Irix 5.2) do not like that. */ -enum { ActionNone, ActionQuit, ActionReset, ActionDisplay, +enum { ActionNone, ActionQuit, ActionReset, ActionDisplay, ActionCompact, ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS, #ifdef HAVE_IPINFO ActionII, ActionAS, diff --git a/ui/mtr.h b/ui/mtr.h index 8be1da9a..252d9541 100644 --- a/ui/mtr.h +++ b/ui/mtr.h @@ -116,7 +116,7 @@ struct mtr_ctl { ForceMaxPing:1, use_dns:1, show_ips:1, - enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5; + enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5, CompactLayout:1; }; /* dynamic field drawing */ diff --git a/ui/select.c b/ui/select.c index 1a9f5c21..b44fc531 100644 --- a/ui/select.c +++ b/ui/select.c @@ -224,6 +224,10 @@ void select_loop( ctl->display_mode = (ctl->display_mode + 1) % DisplayModeMAX; break; + case ActionCompact: + ctl->CompactLayout = !ctl->CompactLayout; + display_clear(ctl); + break; case ActionClear: display_clear(ctl); break; From 83fc8e2b2580053dfd6abc76b26748e504008252 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Thu, 15 Aug 2024 14:31:46 +0100 Subject: [PATCH 2/2] mtr.8.in: spell --mark argument type properly [skip ci] --- man/mtr.8.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/mtr.8.in b/man/mtr.8.in index 84baac6f..47c0cfee 100644 --- a/man/mtr.8.in +++ b/man/mtr.8.in @@ -453,7 +453,7 @@ a short interval, will use up a lot of file descriptors. Set the mark for each packet sent through this socket similar to the netfilter MARK target but socket-based. .I MARK -is 32 unsigned integer. See +is a 32-bit unsigned integer. See .BR socket (7) for full description of this socket option. .SH ENVIRONMENT