From 10ef89219027856c65b0138203f338ecb2ce5054 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 15 Feb 2019 15:36:05 -0800 Subject: 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. --- toys/posix/ps.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'toys/posix') 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); } -- cgit v1.2.3