From: Darafei Praliaskouski Date: Thu, 7 May 2026 20:22:25 +0000 (+0400) Subject: feat(curses): add report snapshot on exit X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=refs%2Fpull%2F643%2Fhead;p=thirdparty%2Fmtr.git feat(curses): add report snapshot on exit --- diff --git a/bash-completion/mtr b/bash-completion/mtr index 63b153b..bc60346 100644 --- a/bash-completion/mtr +++ b/bash-completion/mtr @@ -54,7 +54,8 @@ _mtr_module() --filename --inet --inet6 --udp --tcp --address --first-ttl --max-ttl --max-unknown --port --localport --psize --bitpattern --interval --gracetime --tos --mpls --timeout --mark --report - --report-wide --report-cycles --json --xml --csv --raw --split + --report-wide --report-on-exit --report-cycles --json --xml --csv + --raw --split --curses --displaymode --gtk --no-dns --show-ips --order --ipinfo --aslookup --help --version ' diff --git a/man/mtr.8.in b/man/mtr.8.in index 8684ac5..a3d05c6 100644 --- a/man/mtr.8.in +++ b/man/mtr.8.in @@ -17,6 +17,9 @@ mtr \- a network diagnostic tool .B \-\-report-wide\c ] [\c +.B \-\-report\-on\-exit\c +] +[\c .B \-\-xml\c ] [\c @@ -202,6 +205,11 @@ mode. When in this mode, .B mtr will not cut hostnames in the report. .TP +.B \-\-report\-on\-exit +Use this option with the curses interface to print a report snapshot after +leaving curses mode. This keeps the last trace visible in terminals that switch +to an alternate screen while curses is active. +.TP .B \-x\fR, \fB\-\-xml Use this option to tell .B mtr diff --git a/test/cmdparse.py b/test/cmdparse.py index 6a093d2..1aaf166 100755 --- a/test/cmdparse.py +++ b/test/cmdparse.py @@ -119,6 +119,14 @@ class TestMtrCommandParse(unittest.TestCase): self.assertIn('Drop', reply.stdout) self.assertIn('Jint', reply.stdout) + def test_help_lists_report_on_exit(self): + 'Test that the curses exit snapshot option remains advertised.' + + reply = self.run_mtr('--help') + + self.assertEqual(reply.returncode, 0) + self.assertIn('--report-on-exit', reply.stdout) + def test_port_with_tcp_succeeds_flag(self): 'Test that specifying -P with -T (TCP) succeeds.' diff --git a/ui/display.c b/ui/display.c index a076154..25c3dc4 100644 --- a/ui/display.c +++ b/ui/display.c @@ -146,6 +146,8 @@ void display_close( asn_close(ctl); #endif mtr_curses_close(); + if (ctl->ReportOnExit) + report_close(ctl); break; #endif case DisplaySplit: diff --git a/ui/mtr.c b/ui/mtr.c index 98977f6..671204d 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -127,6 +127,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out) #endif fputs(" -r, --report output using report mode\n", out); fputs(" -w, --report-wide output wide report\n", out); + fputs(" --report-on-exit print report after curses exits\n", out); fputs(" -c, --report-cycles COUNT set the number of pings sent\n", out); #ifdef HAVE_JANSSON fputs(" -j, --json output json\n", out); @@ -420,12 +421,13 @@ static void parse_arg( */ enum { OPT_DISPLAYMODE = CHAR_MAX + 1, - OPT_IPINFO4 = CHAR_MAX + 2, + OPT_REPORT_ON_EXIT = CHAR_MAX + 2, + OPT_IPINFO4 = CHAR_MAX + 3, #ifdef ENABLE_IPV6 - OPT_IPINFO6 = CHAR_MAX + 3, - OPT_CACHE = CHAR_MAX + 4, + OPT_IPINFO6 = CHAR_MAX + 4, + OPT_CACHE = CHAR_MAX + 5, #else - OPT_CACHE = CHAR_MAX + 3, + OPT_CACHE = CHAR_MAX + 4, #endif /* ifdef ENABLE_IPV6 */ }; static const struct option long_options[] = { @@ -441,6 +443,7 @@ static void parse_arg( {"report", 0, NULL, 'r'}, {"report-wide", 0, NULL, 'w'}, + {"report-on-exit", 0, NULL, OPT_REPORT_ON_EXIT}, {"xml", 0, NULL, 'x'}, #ifdef HAVE_CURSES {"curses", 0, NULL, 't'}, @@ -535,6 +538,9 @@ static void parse_arg( ctl->reportwide = 1; ctl->DisplayMode = DisplayReport; break; + case OPT_REPORT_ON_EXIT: + ctl->ReportOnExit = 1; + break; #ifdef HAVE_CURSES case 't': ctl->DisplayMode = DisplayCurses; diff --git a/ui/mtr.h b/ui/mtr.h index c4fd2eb..09df6db 100644 --- a/ui/mtr.h +++ b/ui/mtr.h @@ -122,7 +122,8 @@ struct mtr_ctl { ForceMaxPing:1, use_dns:1, cache:1, show_ips:1, - enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5, CompactLayout:1; + enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5, + CompactLayout:1, ReportOnExit:1; #ifdef HAVE_IPINFO #ifdef ENABLE_IPV6 char *ipinfo_provider6;