summaryrefslogtreecommitdiffstats
path: root/src/cgtop/cgtop.c
diff options
context:
space:
mode:
authorCharles Duffy <chaduffy@cisco.com>2015-05-28 00:30:11 +0200
committerCharles Duffy <chaduffy@cisco.com>2015-06-10 02:39:16 +0200
commitdcc7aacd67505b812214058dc9a8d321d8d98c7c (patch)
treeed77c970e62e6530193cd6b7084a7a6829483b58 /src/cgtop/cgtop.c
parentcgtop: allow user to force looping behavior even in non-TTY mode (diff)
downloadsystemd-dcc7aacd67505b812214058dc9a8d321d8d98c7c.tar.xz
systemd-dcc7aacd67505b812214058dc9a8d321d8d98c7c.zip
cgtop: more sensible flushing behavior w/ non-TTY output
- Explicitly flush stdout before sleep between iterations - Only clear user keystrokes when output is to TTY - Add a newline between output batches when output is not to TTY
Diffstat (limited to '')
-rw-r--r--src/cgtop/cgtop.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index d04d6f225c..3a2842dac6 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -749,6 +749,10 @@ int main(int argc, char *argv[]) {
if (arg_iterations && iteration >= arg_iterations)
break;
+ if (!on_tty()) /* non-TTY: Empty newline as delimiter between polls */
+ fputs("\n", stdout);
+ fflush(stdout);
+
if (arg_batch) {
usleep(last_refresh + arg_delay - t);
} else {
@@ -762,8 +766,10 @@ int main(int argc, char *argv[]) {
}
}
- fputs("\r \r", stdout);
- fflush(stdout);
+ if (on_tty()) { /* TTY: Clear any user keystroke */
+ fputs("\r \r", stdout);
+ fflush(stdout);
+ }
if (arg_batch)
continue;