Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcurses PR/45791: Nat Sloss: getnstr erase character w...



details:   https://anonhg.NetBSD.org/src/rev/5005ff55b084
branches:  trunk
changeset: 772523:5005ff55b084
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jan 06 22:20:54 2012 +0000

description:
PR/45791: Nat Sloss: getnstr erase character weirdness
Fix processing of backspace erase char and char left.

diffstat:

 lib/libcurses/getstr.c |  45 +++++++++++++++++++++++++++++----------------
 1 files changed, 29 insertions(+), 16 deletions(-)

diffs (107 lines):

diff -r 92c22b14f234 -r 5005ff55b084 lib/libcurses/getstr.c
--- a/lib/libcurses/getstr.c    Fri Jan 06 22:14:04 2012 +0000
+++ b/lib/libcurses/getstr.c    Fri Jan 06 22:20:54 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getstr.c,v 1.20 2007/05/28 15:01:55 blymn Exp $        */
+/*     $NetBSD: getstr.c,v 1.21 2012/01/06 22:20:54 christos Exp $     */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -35,10 +35,11 @@
 #if 0
 static char sccsid[] = "@(#)getstr.c   8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: getstr.c,v 1.20 2007/05/28 15:01:55 blymn Exp $");
+__RCSID("$NetBSD: getstr.c,v 1.21 2012/01/06 22:20:54 christos Exp $");
 #endif
 #endif                         /* not lint */
 
+#include <ctype.h>
 #include "curses.h"
 #include "curses_private.h"
 
@@ -161,12 +162,12 @@
 __wgetnstr(WINDOW *win, char *str, int n)
 {
        char *ostr, ec, kc;
-       int c, oldx, remain;
+       int c, xpos, oldx, remain;
 
        ostr = str;
        ec = erasechar();
        kc = killchar();
-       oldx = win->curx;
+       xpos = oldx = win->curx;
        _DIAGASSERT(n == -1 || n > 1);
        remain = n - 1;
 
@@ -182,17 +183,23 @@
                        *str = '\0';
                        if (str != ostr) {
                                if ((char) c == ec) {
-                                       mvwaddch(win, win->cury, win->curx,
-                                           ' ');
-                                       wmove(win, win->cury, win->curx - 1);
+                                       mvwaddch(win, win->cury, xpos, ' ');
+                                       if (xpos > oldx)
+                                               mvwaddch(win, win->cury,
+                                                   xpos - 1, ' ');
+                                       if (win->curx > xpos - 1)
+                                               wmove(win, win->cury, xpos - 1);
+                                       xpos--;
                                }
                                if (c == KEY_BACKSPACE || c == KEY_LEFT) {
                                        /* getch() displays the key sequence */
+                                       mvwaddch(win, win->cury, win->curx,
+                                           ' ');
                                        mvwaddch(win, win->cury, win->curx - 1,
                                            ' ');
-                                       mvwaddch(win, win->cury, win->curx - 2,
-                                           ' ');
-                                       wmove(win, win->cury, win->curx - 1);
+                                       if (win->curx > xpos)
+                                               wmove(win, win->cury, xpos - 1);
+                                       xpos--;
                                }
                                str--;
                                if (n != -1) {
@@ -200,11 +207,12 @@
                                        remain++;
                                }
                        } else {        /* str == ostr */
-                               if (c == KEY_BACKSPACE || c == KEY_LEFT)
-                                       /* getch() displays the other keys */
+                               /* getch() displays the other keys */
+                               if (win->curx > oldx)
                                        mvwaddch(win, win->cury, win->curx - 1,
                                            ' ');
                                wmove(win, win->cury, oldx);
+                               xpos = oldx;
                        }
                } else if (c == kc) {
                        *str = '\0';
@@ -229,15 +237,20 @@
                        wmove(win, win->cury, oldx);
                } else if (c >= KEY_MIN && c <= KEY_MAX) {
                        /* getch() displays these characters */
-                       mvwaddch(win, win->cury, win->curx - 1, ' ');
-                       wmove(win, win->cury, win->curx - 1);
+                       mvwaddch(win, win->cury, xpos, ' ');
+                       wmove(win, win->cury, xpos);
                } else {
                        if (remain) {
+                               if (iscntrl((unsigned char)c)) {
+                                       mvwaddch(win, win->cury, xpos, ' ');
+                                       wmove(win, win->cury, xpos + 1);
+                               }
                                str++;
+                               xpos++;
                                remain--;
                        } else {
-                               mvwaddch(win, win->cury, win->curx - 1, ' ');
-                               wmove(win, win->cury, win->curx - 1);
+                               mvwaddch(win, win->cury, xpos, ' ');
+                               wmove(win, win->cury, xpos - 1);
                        }
                }
        }



Home | Main Index | Thread Index | Old Index