]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Add a compact mode in curses
authorDenis Afonin <den@raznix>
Sat, 3 Aug 2024 16:16:57 +0000 (19:16 +0300)
committerDenis Afonin <den@raznix>
Sat, 3 Aug 2024 16:16:57 +0000 (19:16 +0300)
ui/curses.c
ui/display.h
ui/mtr.h
ui/select.c

index d01e178c0d5a641fbe1f1d83a5d961004e38f210..3b295f22935c7b90ea1253a0c74abf65ab00bc3f 100644 (file)
@@ -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);
index 0c16e90cc01d9df92660afbf56aecc1a8d62f2a6..b4eca77c757d127e6e3ec4350220606d854345ad 100644 (file)
@@ -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,
index 8be1da9a161744a2f71fbdb08fa614868ca5599e..252d954112504c955d6255e8ca98124839bbc1fc 100644 (file)
--- 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 */
index 1a9f5c215f2d01cf2c12828003878efd42124c84..b44fc5312ac7f590f4eae521576474ea9747a892 100644 (file)
@@ -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;