From 406d4c978ac841b34c8725e67da9962957da1848 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 15 Apr 2016 18:38:53 -0700 Subject: Fix top -b. Batch mode should never output terminal escape sequences, should ignore the keyboard, and should include a gap between datasets. --- toys/posix/ps.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'toys') 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; inow+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++; -- cgit v1.2.3