From 894aa5212b1011706a4f284d9baf5cb676dd3df3 Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Mon, 19 Feb 2018 23:41:49 +0200 Subject: [PATCH] Keep cursor within bounds in os_read_line. Maximum scrpos is width - 1 even if len == width. Then the cursor will stay on the last character because there is no room to the right of it. #42: Handle terminal resizing --- src/curses/ux_input.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index e4d3f4c..877e0f1 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -488,13 +488,16 @@ zchar os_read_line (int bufmax, zchar *buf, int timeout, int width, unix_set_global_timeout(timeout); for (;;) { int x2, max; + if (scrpos >= width) + scrpos = width - 1; move(y, x + scrpos); /* Maybe there's a cleaner way to do this, but refresh() is */ /* still needed here to print spaces. --DG */ refresh(); ch = unix_read_char(1); getyx(stdscr, y, x2); - max = MIN(h_screen_width - margin, bufmax); + width = h_screen_width - margin; + max = MIN(width, bufmax); /* The screen has shrunk and input no longer fits. Chop. */ if (len > max) { len = max; -- 2.34.1