Skip to content

Commit e130318

Browse files
author
Denis Afonin
committed
Add a compact mode in curses
1 parent 852e561 commit e130318

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

ui/curses.c

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ int mtr_curses_keyaction(
172172
return ActionReset;
173173
case 'd':
174174
return ActionDisplay;
175+
case 'c':
176+
return ActionCompact;
175177
case 'e':
176178
return ActionMPLS;
177179
case 'n':
@@ -345,6 +347,7 @@ int mtr_curses_keyaction(
345347
printw(" ?|h help\n");
346348
printw(" p pause (SPACE to resume)\n");
347349
printw(" d switching display mode\n");
350+
printw(" c switching compact mode\n");
348351
printw(" e toggle MPLS information on/off\n");
349352
printw(" n toggle DNS on/off\n");
350353
printw(" r reset all counters\n");
@@ -689,7 +692,7 @@ void mtr_curses_redraw(
689692
erase();
690693
getmaxyx(stdscr, __unused_int, maxx);
691694

692-
rowstat = 5;
695+
rowstat = !ctl->CompactLayout;
693696

694697
move(0, 0);
695698
attron(A_BOLD);
@@ -698,34 +701,38 @@ void mtr_curses_redraw(
698701
pwcenter(buf);
699702
attroff(A_BOLD);
700703

701-
mvprintw(1, 0, "%s (%s) -> %s (%s)",
704+
mvprintw(rowstat, 0, "%s (%s) -> %s (%s)",
702705
ctl->LocalHostname, net_localaddr(),
703706
ctl->Hostname, net_remoteaddr());
704707
t = time(NULL);
705-
mvprintw(1, maxx - 25, "%s", iso_time(&t));
706-
printw("\n");
708+
mvprintw(rowstat, maxx - 25, "%s", iso_time(&t));
709+
if (rowstat) {
710+
printw("\n");
707711

708-
printw("Keys: ");
709-
attron(A_BOLD);
710-
printw("H");
711-
attroff(A_BOLD);
712-
printw("elp ");
713-
attron(A_BOLD);
714-
printw("D");
715-
attroff(A_BOLD);
716-
printw("isplay mode ");
717-
attron(A_BOLD);
718-
printw("R");
719-
attroff(A_BOLD);
720-
printw("estart statistics ");
721-
attron(A_BOLD);
722-
printw("O");
723-
attroff(A_BOLD);
724-
printw("rder of fields ");
725-
attron(A_BOLD);
726-
printw("q");
727-
attroff(A_BOLD);
728-
printw("uit\n");
712+
printw("Keys: ");
713+
attron(A_BOLD);
714+
printw("H");
715+
attroff(A_BOLD);
716+
printw("elp ");
717+
attron(A_BOLD);
718+
printw("D");
719+
attroff(A_BOLD);
720+
printw("isplay mode ");
721+
attron(A_BOLD);
722+
printw("R");
723+
attroff(A_BOLD);
724+
printw("estart statistics ");
725+
attron(A_BOLD);
726+
printw("O");
727+
attroff(A_BOLD);
728+
printw("rder of fields ");
729+
attron(A_BOLD);
730+
printw("q");
731+
attroff(A_BOLD);
732+
printw("uit\n");
733+
}
734+
735+
rowstat = rowstat ? 5 : 1;
729736

730737
if (ctl->display_mode == DisplayModeDefault) {
731738
for (i = 0; i < MAXFLD; i++) {
@@ -761,8 +768,10 @@ void mtr_curses_redraw(
761768
maxx <= SAVED_PINGS + padding ? maxx - padding : SAVED_PINGS;
762769
startstat = padding - 2;
763770

764-
snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);
765-
mvprintw(rowstat - 1, startstat, "%s", msg);
771+
if (rowstat > 1) {
772+
snprintf(msg, sizeof(msg), " Last %3d pings", max_cols);
773+
mvprintw(rowstat - 1, startstat, "%s", msg);
774+
}
766775

767776
attroff(A_BOLD);
768777
move(rowstat, 0);

ui/display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
/* Don't put a trailing comma in enumeration lists. Some compilers
2222
(notably the one on Irix 5.2) do not like that. */
23-
enum { ActionNone, ActionQuit, ActionReset, ActionDisplay,
23+
enum { ActionNone, ActionQuit, ActionReset, ActionDisplay, ActionCompact,
2424
ActionClear, ActionPause, ActionResume, ActionMPLS, ActionDNS,
2525
#ifdef HAVE_IPINFO
2626
ActionII, ActionAS,

ui/mtr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct mtr_ctl {
116116
ForceMaxPing:1,
117117
use_dns:1,
118118
show_ips:1,
119-
enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5;
119+
enablempls:1, dns:1, reportwide:1, Interactive:1, DisplayMode:5, CompactLayout:1;
120120
};
121121

122122
/* dynamic field drawing */

ui/select.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ void select_loop(
224224
ctl->display_mode =
225225
(ctl->display_mode + 1) % DisplayModeMAX;
226226
break;
227+
case ActionCompact:
228+
ctl->CompactLayout = !ctl->CompactLayout;
229+
display_clear(ctl);
230+
break;
227231
case ActionClear:
228232
display_clear(ctl);
229233
break;

0 commit comments

Comments
 (0)