aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-02-15 15:36:05 -0800
committerRob Landley <rob@landley.net>2019-02-16 16:20:04 -0600
commit10ef89219027856c65b0138203f338ecb2ce5054 (patch)
tree9707f8a537408aa294c997e2b7daef8a39ef1d6c
parenta7a3c411fdb002452dea75db517a0402fcdd3223 (diff)
downloadtoybox-10ef89219027856c65b0138203f338ecb2ce5054.tar.gz
top: make the column header span the terminal.
This also makes everything more readable by separating out the -b no formatting case. The whitespace trimming for -b isn't strictly necessary, but it looks weird if we output unnecessary spaces at the end of the line in -b mode, and we've fixed it before, so let's not regress here. It also seems more logical to do this in the one place where it actually happens.
-rw-r--r--toys/posix/ps.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index faddf685..19292c98 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1423,10 +1423,11 @@ static int header_line(int line, int rev)
{
if (!line) return 0;
- if (FLAG(b)) rev = 0;
-
- printf("%s%*.*s%s%s\n", rev ? "\033[7m" : "", -TT.width*!!FLAG(b), TT.width,
- toybuf, rev ? "\033[0m" : "", FLAG(b) ? "" : "\r");
+ if (FLAG(b)) puts(toybuf);
+ else {
+ printf("%s%-*.*s%s\r\n", rev?"\033[7m":"", rev?TT.width:0, TT.width, toybuf,
+ rev?"\033[0m":"");
+ }
return line-1;
}
@@ -1635,6 +1636,7 @@ static void top_common(
pos[-1] = '[';
if (!isspace(was) && isspace(is) && i==TT.sortpos+1) *pos = ']';
}
+ if (FLAG(b)) while (isspace(*(pos-1))) --pos;
*pos = 0;
lines = header_line(lines, 1);
}