Keep cursor within bounds in os_read_line.
authorTimo Korvola <tkorvola@iki.fi>
Mon, 19 Feb 2018 21:41:49 +0000 (23:41 +0200)
committerTimo Korvola <tkorvola@iki.fi>
Mon, 19 Feb 2018 21:42:58 +0000 (23:42 +0200)
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

index e4d3f4c8b3d8e2595de0b8242f3fb9c55bcb43cf..877e0f19e3e0c510dc58299c80dc20117c049d67 100644 (file)
@@ -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;