From b4f202f89f2a32bb74f910a2b6c8e277a07ffd02 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sun, 6 May 2012 16:47:30 +0200 Subject: [PATCH] xbps-bin/util.c: find out terminal columns and use it to print transaction. --- bin/xbps-bin/util.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/xbps-bin/util.c b/bin/xbps-bin/util.c index b953e08f..c209c942 100644 --- a/bin/xbps-bin/util.c +++ b/bin/xbps-bin/util.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include "defs.h" @@ -211,6 +212,13 @@ print_package_line(const char *str, bool reset) { static size_t cols; static bool first; + struct winsize ws; + size_t maxcols; + + if (ioctl(1, TIOCGWINSZ, &ws) == 0) + maxcols = ws.ws_col; + else + maxcols = 80; if (reset) { cols = 0; @@ -218,7 +226,7 @@ print_package_line(const char *str, bool reset) return; } cols += strlen(str) + 4; - if (cols <= 80) { + if (cols <= maxcols) { if (first == false) { printf(" "); first = true;