Skip to content

Commit

Permalink
Truncate output if it's wider than 12 chars
Browse files Browse the repository at this point in the history
Early version of the patch OK'd by martin@.

Fixes #1855.
  • Loading branch information
fgsch committed Mar 4, 2016
1 parent fd39f38 commit 81d5d46
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion bin/varnishstat/varnishstat_curses.c
Expand Up @@ -65,6 +65,8 @@
#define COLW 14
#define COLW_NAME_MIN 24

#define VALUE_MAX 999999999999

struct ma {
unsigned n, nmax;
double acc;
Expand Down Expand Up @@ -714,6 +716,17 @@ print_bytes(WINDOW *w, double val)
wprintw(w, " %12.2f%c", val, q);
}

static void
print_trunc(WINDOW *w, uintmax_t val)
{
if (val > VALUE_MAX) {
while (val > VALUE_MAX)
val /= 1000;
wprintw(w, " %9ju...", val);
} else
wprintw(w, " %12ju", val);
}

static void
draw_line_bytes(WINDOW *w, int y, int x, int X, struct pt *pt)
{
Expand All @@ -740,7 +753,7 @@ draw_line_bytes(WINDOW *w, int y, int x, int X, struct pt *pt)
if (scale && pt->cur > 1024)
print_bytes(w, (double)pt->cur);
else
wprintw(w, " %12ju", (uintmax_t)pt->cur);
print_trunc(w, (uintmax_t)pt->cur);
break;
case COL_CHG:
if (pt->t_last)
Expand Down

0 comments on commit 81d5d46

Please sign in to comment.