2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
26 ** The routine wgetstr().
30 #include <curses.priv.h>
33 MODULE_ID("$Id: lib_getstr.c,v 1.11 1997/02/01 23:22:54 tom Exp $")
36 * This wipes out the last character, no matter whether it was a tab, control
37 * or other character, and handles reverse wraparound.
39 static char *WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed)
50 while (win->_cury < y1
51 || (win->_cury == y1 && win->_curx < x1))
60 int wgetnstr(WINDOW *win, char *str, int maxlen)
63 bool oldnl, oldecho, oldraw, oldcbreak, oldkeypad;
70 T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen));
72 GET_TTY(cur_term->Filedes, &buf);
77 oldcbreak = SP->_cbreak;
78 oldkeypad = win->_use_keypad;
91 if (is_wintouched(win) || (win->_flags & _HASMOVED))
94 while ((ch = wgetch(win)) != ERR) {
96 * Some terminals (the Wyse-50 is the most common) generate
97 * a \n from the down-arrow key. With this logic, it's the
98 * user's choice whether to set kcud=\n for wgetch();
99 * terminating *getstr() with \n should work either way.
106 if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
108 str = WipeOut(win, y, x, oldstr, str, oldecho);
110 } else if (ch == killc) {
111 while (str > oldstr) {
112 str = WipeOut(win, y, x, oldstr, str, oldecho);
114 } else if (ch >= KEY_MIN
115 || (maxlen >= 0 && str - oldstr >= maxlen)) {
119 if (oldecho == TRUE) {
120 if (waddch(win, ch) == ERR) {
122 * We can't really use the lower-right
123 * corner for input, since it'll mess
124 * up bookkeeping for erases.
126 win->_flags &= ~_WRAPPED;
128 str = WipeOut(win, y, x, oldstr, str, oldecho);
137 win->_flags &= ~_WRAPPED;
138 if (win->_cury < win->_maxy)
142 /* Restore with a single I/O call, to fix minor asymmetry between
148 SP->_cbreak = oldcbreak;
150 SET_TTY(cur_term->Filedes, &buf);
152 if (oldkeypad == FALSE)
159 T(("wgetnstr returns %s", _nc_visbuf(oldstr)));