[Toybox] [PATCH] top: hide the cursor in interactive mode.

enh enh at google.com
Wed Feb 13 14:48:00 PST 2019


Matches traditional top.
---
 toys/posix/ps.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index eff980f3..ce13d4f6 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1431,6 +1431,11 @@ static int header_line(int line, int rev)
   return line-1;
 }

+static void top_cursor_cleanup(void)
+{
+  tty_esc("?25h");
+}
+
 static void top_common(
   int (*filter)(long long *oslot, long long *nslot, int milis))
 {
@@ -1447,8 +1452,12 @@ static void top_common(
   int i, lines, topoff = 0, done = 0;
   char stdout_buf[BUFSIZ];

-  // Avoid flicker in interactive mode.
-  if (!FLAG(b)) setbuf(stdout, stdout_buf);
+  // Avoid flicker and hide the cursor in interactive mode.
+  if (!FLAG(b)) {
+    setbuf(stdout, stdout_buf);
+    tty_esc("?25l");
+    sigatexit(top_cursor_cleanup);
+  }

   toys.signal = SIGWINCH;
   TT.bits = get_headers(TT.fields, toybuf, sizeof(toybuf));
-- 
2.20.1.791.gb4d0f1c61a-goog
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-top-hide-the-cursor-in-interactive-mode.patch
Type: text/x-patch
Size: 1194 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20190213/85370522/attachment-0002.bin>


More information about the Toybox mailing list