Refine V=0 command logging (#602)

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.
This commit is contained in:
Connor 2022-09-13 01:48:28 -07:00 committed by GitHub
parent 22b63d0b98
commit ed5b763a0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -335,7 +335,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;
}
}
@ -1301,24 +1300,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) {