On Mon, 13 Jan 2014, Gregor Best wrote:
> On Mon, Jan 13, 2014 at 05:04:28PM +0000, Stuart Henderson wrote:
> > If anyone is interested in looking at a signal problem in top,
> > here's a small but annoying bug..
> >
> > - run top in an xterm
> > - resize the window
> > - try to use an interactive command that takes an argument, e.g. "s"
> > or "g" (doesn't happen with commands like "S" or "H" that work immediately)
> >
> > Often, pressing the command key just refreshes the screen, it takes
> > multiple attempts for the command to take effect (sometimes just a
> > couple, sometimes loads of attempts).
> > [...]
>
> The patch below seems to fix that for me. resizeterm() does a
> putchar(KEY_RESIZE), part of which then gets interpreted as a command
> parameter in rundisplay().
I think you meant "ungetch(KEY_RESIZE)", but that pointed me at the
getnstr() manpage, which notes that it returns KEY_RESIZE if there was a
pending resize event. Changing readline() to loop on getnstr() while it
returns that, resetting the cursor position each time, seems to fix the
problem in my testing.
Philip Guenther
Index: display.c
===================================================================
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.46
diff -u -p -r1.46 display.c
--- display.c 28 Nov 2013 18:24:55 -0000 1.46
+++ display.c 13 Jan 2014 20:37:38 -0000
@@ -641,9 +641,12 @@ readline(char *buffer, int size)
/* allow room for null terminator */
size -= 1;
- if (smart_terminal)
- getnstr(buffer, size);
- else
+ if (smart_terminal) {
+ int y, x;
+ getyx(stdscr, y, x);
+ while (getnstr(buffer, size) == KEY_RESIZE)
+ move(y, x);
+ } else
return readlinedumb(buffer, size);
cnt = strlen(buffer);