My earlier trick to ensure that we buffer whole screens full works fine
on glibc, but both bionic and musl have a tiny 1024-byte BUFSIZ that
makes it unsuitable for this kind of use, even on laptop screens.

Explicitly say 8192, since 4096 is slightly too small for my larger
laptop's screen (and I don't use a particularly small font).

At some point we should probably move this into tty.c, dynamically
allocate based on screen size (plus space for escape sequences/non-ASCII
characters), and track SIGWINCH in case the window grows. But this stops
top and vi flickering today, which is good enough for now. (Amusingly, I
hit the vi problem -- which is actually much worse, for dense strace
output -- while debugging the top problem, while debugging the ps
problem, while debugging the thing I was actually supposed to be doing
_yesterday_. So definitely time to back out of a few rat holes!)
---
 toys/pending/vi.c | 2 +-
 toys/posix/ps.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
From 1d975459a3815e149c698e69e4b67c761d58c5d8 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Thu, 23 Feb 2023 12:36:14 -0800
Subject: [PATCH] ps, vi: fix flicker.

My earlier trick to ensure that we buffer whole screens full works fine
on glibc, but both bionic and musl have a tiny 1024-byte BUFSIZ that
makes it unsuitable for this kind of use, even on laptop screens.

Explicitly say 8192, since 4096 is slightly too small for my larger
laptop's screen (and I don't use a particularly small font).

At some point we should probably move this into tty.c, dynamically
allocate based on screen size (plus space for escape sequences/non-ASCII
characters), and track SIGWINCH in case the window grows. But this stops
top and vi flickering today, which is good enough for now. (Amusingly, I
hit the vi problem -- which is actually much worse, for dense strace
output -- while debugging the top problem, while debugging the ps
problem, while debugging the thing I was actually supposed to be doing
_yesterday_. So definitely time to back out of a few rat holes!)
---
 toys/pending/vi.c | 2 +-
 toys/posix/ps.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/toys/pending/vi.c b/toys/pending/vi.c
index e5a8e058..acc691a3 100644
--- a/toys/pending/vi.c
+++ b/toys/pending/vi.c
@@ -1520,7 +1520,7 @@ static void draw_page()
 
 void vi_main(void)
 {
-  char stdout_buf[BUFSIZ];
+  char stdout_buf[8192];
   char keybuf[16] = {0};
   char vi_buf[16] = {0};
   char utf8_code[8] = {0};
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 1fdfc17c..5b0b58c9 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1521,7 +1521,7 @@ static void top_common(
     "iow", "irq", "sirq", "host"};
   unsigned tock = 0;
   int i, lines, topoff = 0, done = 0;
-  char stdout_buf[BUFSIZ];
+  char stdout_buf[8192];
 
   if (!TT.fields) perror_exit("no -o");
 
-- 
2.39.2.722.g9855ee24e9-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to