mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 07:29:23 +00:00
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:
parent
22b63d0b98
commit
ed5b763a0c
1 changed files with 6 additions and 10 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue