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.
This commit is contained in:
Connor Olding 2022-09-08 11:22:36 +00:00
parent b73e35c6fa
commit b4374e9668

View file

@ -333,7 +333,6 @@ int GetTerminalWidth(void) {
} else { } else {
ws.ws_col = 0; ws.ws_col = 0;
ioctl(2, TIOCGWINSZ, &ws); ioctl(2, TIOCGWINSZ, &ws);
if (!ws.ws_col) ws.ws_col = 80;
return ws.ws_col; return ws.ws_col;
} }
} }
@ -1299,24 +1298,21 @@ int main(int argc, char *argv[]) {
if (!outpath) outpath = shortened; if (!outpath) outpath = shortened;
n = strlen(action); n = strlen(action);
appends(&command, action); appends(&command, action);
if (n < 15) { do appendw(&command, ' '), ++n;
while (n++ < 15) { while (n < 15);
appendw(&command, ' ');
}
} else {
appendw(&command, ' ');
++n;
}
appends(&command, outpath); appends(&command, outpath);
n += strlen(outpath); n += strlen(outpath);
appendw(&command, '\r');
m = GetTerminalWidth(); m = GetTerminalWidth();
if (m > 3 && n > m) { if (m > 3 && n > m) {
appendd(&output, command, m - 3); appendd(&output, command, m - 3);
appendw(&output, READ32LE("...")); appendw(&output, READ32LE("..."));
} else { } else {
if (n < m && (__nocolor || !ischardev(2))) {
while (n < m) appendw(&command, ' '), ++n;
}
appendd(&output, command, n); appendd(&output, command, n);
} }
appendw(&output, m > 0 ? '\r' : '\n');
} else { } else {
n = 0; n = 0;
if (verbose >= 3) { if (verbose >= 3) {