From 231cf864f1b06ccd92f53aa6a6b70dfec91bd0f5 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 5 Nov 2013 14:22:53 +0100 Subject: monitor: Fallback to 80 columns terminal if not able to get real size This makes num_columns always return valid number of columns, which is expected by print_packets function. This also fix garbage prints while using btmon via adb shell. --- monitor/display.c | 8 ++++---- monitor/display.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'monitor') diff --git a/monitor/display.c b/monitor/display.c index b8dce1f4a..af4171fc8 100644 --- a/monitor/display.c +++ b/monitor/display.c @@ -58,10 +58,10 @@ int num_columns(void) if (__builtin_expect(!!(cached_num_columns < 0), 0)) { struct winsize ws; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) - return -1; - - if (ws.ws_col > 0) + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0 || + ws.ws_col == 0) + cached_num_columns = FALLBACK_TERMINAL_WIDTH; + else cached_num_columns = ws.ws_col; } diff --git a/monitor/display.h b/monitor/display.h index 6139cc2eb..885eb3412 100644 --- a/monitor/display.h +++ b/monitor/display.h @@ -40,6 +40,8 @@ bool use_color(void); #define COLOR_ERROR "\x1B[1;31m" +#define FALLBACK_TERMINAL_WIDTH 80 + #define print_indent(indent, color1, prefix, title, color2, fmt, args...) \ do { \ printf("%*c%s%s%s%s" fmt "%s\n", (indent), ' ', \ -- cgit v1.2.3