[master] 81d5d46 Truncate output if it's wider than 12 chars

Federico G. Schwindt fgsch at lodoss.net
Fri Mar 4 14:20:37 CET 2016


commit 81d5d4626690fdff586a7a40a89279d3deb9bb60
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Fri Mar 4 09:00:47 2016 +0000

    Truncate output if it's wider than 12 chars
    
    Early version of the patch OK'd by martin at .
    
    Fixes #1855.

diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 484d369..01c180c 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -65,6 +65,8 @@
 #define COLW			14
 #define COLW_NAME_MIN		24
 
+#define VALUE_MAX		999999999999
+
 struct ma {
 	unsigned n, nmax;
 	double acc;
@@ -715,6 +717,17 @@ print_bytes(WINDOW *w, double val)
 }
 
 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)
 {
 	enum {
@@ -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)



More information about the varnish-commit mailing list