aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-04-15 18:38:53 -0700
committerRob Landley <rob@landley.net>2016-04-16 19:58:40 -0500
commit406d4c978ac841b34c8725e67da9962957da1848 (patch)
treeb96e6fe7e2fdd3e5d07cf120ea94082a3c390377 /toys/posix
parentdf6a96d3ed0a355df0bd0a3468b77c32871ef5ca (diff)
downloadtoybox-406d4c978ac841b34c8725e67da9962957da1848.tar.gz
Fix top -b.
Batch mode should never output terminal escape sequences, should ignore the keyboard, and should include a gap between datasets.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/ps.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 26b4a4ea..a1e1981a 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1144,6 +1144,8 @@ static int header_line(int line, int rev)
{
if (!line) return 0;
+ if (toys.optflags&FLAG_b) rev = 0;
+
printf("%s%*.*s%s\r\n", rev ? "\033[7m" : "",
(toys.optflags&FLAG_b) ? 0 : -TT.width, TT.width, toybuf,
rev ? "\033[0m" : "");
@@ -1339,7 +1341,8 @@ static void top_common(
*pos = 0;
lines = header_line(lines, 1);
}
- if (!recalc) printf("\033[%dH\033[J", 1+TT.height-lines);
+ if (!recalc && !(toys.optflags&FLAG_b))
+ printf("\033[%dH\033[J", 1+TT.height-lines);
recalc = 1;
for (i = 0; i<lines && i+topoff<mix.count; i++) {
@@ -1357,6 +1360,14 @@ static void top_common(
if (timeout<=now) timeout = new.whence+TT.top.d;
if (timeout<=now || timeout>now+TT.top.d) timeout = now+TT.top.d;
+ // In batch mode, we ignore the keyboard.
+ if (toys.optflags&FLAG_b) {
+ msleep(timeout-now);
+ // Make an obvious gap between datasets.
+ xputs("\n\n\n");
+ continue;
+ }
+
i = scan_key_getsize(scratch, timeout-now, &TT.width, &TT.height);
if (i==-1 || i==3 || toupper(i)=='Q') {
done++;