mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +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 {
|
} 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1301,24 +1300,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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue