From b4374e9668d7e1e1d75954bebf2e5dd8acd9bfd9 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 8 Sep 2022 11:22:36 +0000 Subject: [PATCH] Refine `V=0` command logging This fixes off-by-one bugs, as well as missing carriage returns caused by command truncation. When the terminal's width is 0 or unknown, line feeds are used instead. Otherwise, the command is padded with spaces to clear the line when the terminal is dumb. --- tool/build/compile.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/tool/build/compile.c b/tool/build/compile.c index 7ba0f1f02..1a2a648fe 100644 --- a/tool/build/compile.c +++ b/tool/build/compile.c @@ -333,7 +333,6 @@ int GetTerminalWidth(void) { } else { ws.ws_col = 0; ioctl(2, TIOCGWINSZ, &ws); - if (!ws.ws_col) ws.ws_col = 80; return ws.ws_col; } } @@ -1299,24 +1298,21 @@ int main(int argc, char *argv[]) { if (!outpath) outpath = shortened; n = strlen(action); appends(&command, action); - if (n < 15) { - while (n++ < 15) { - appendw(&command, ' '); - } - } else { - appendw(&command, ' '); - ++n; - } + do appendw(&command, ' '), ++n; + while (n < 15); appends(&command, outpath); n += strlen(outpath); - appendw(&command, '\r'); m = GetTerminalWidth(); if (m > 3 && n > m) { appendd(&output, command, m - 3); appendw(&output, READ32LE("...")); } else { + if (n < m && (__nocolor || !ischardev(2))) { + while (n < m) appendw(&command, ' '), ++n; + } appendd(&output, command, n); } + appendw(&output, m > 0 ? '\r' : '\n'); } else { n = 0; if (verbose >= 3) {