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(-)
From 5a69e1668117e99f3a2c0847ec960100dd10f91a Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Fri, 15 Feb 2019 15:36:05 -0800
Subject: [PATCH] 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(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index faddf685..82c4eb3d 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);
       }
-- 
2.21.0.rc0.258.g878e2cd30e-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to