1 /****************************************************************************
2 * Copyright (c) 2002,2003 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey 2002 *
31 ****************************************************************************/
36 ** The routine wgetn_wstr().
40 #include <curses.priv.h>
43 MODULE_ID("$Id: lib_get_wstr.c,v 1.6 2003/05/17 21:33:03 tom Exp $")
46 * This wipes out the last character, no matter whether it was a tab, control
47 * or other character, and handles reverse wraparound.
50 WipeOut(WINDOW *win, int y, int x, wchar_t * first, wchar_t * last, bool echoed)
61 while (win->_cury < y1
62 || (win->_cury == y1 && win->_curx < x1))
63 waddch(win, (chtype) ' ');
72 wgetn_wstr(WINDOW *win, wint_t * str, int maxlen)
75 bool oldnl, oldecho, oldraw, oldcbreak;
83 T((T_CALLED("wgetn_wstr(%p,%p, %d)"), win, str, maxlen));
88 _nc_get_tty_mode(&buf);
93 oldcbreak = SP->_cbreak;
102 assert(sizeof(wchar_t) == sizeof(wint_t));
103 oldstr = (wchar_t *) str;
104 tmpstr = (wchar_t *) str;
108 if (is_wintouched(win) || (win->_flags & _HASMOVED))
111 while ((code = wget_wch(win, &ch)) != ERR) {
113 * Map special characters into key-codes.
131 if (code == KEY_CODE_YES) {
133 * Some terminals (the Wyse-50 is the most common) generate a \n
134 * from the down-arrow key. With this logic, it's the user's
135 * choice whether to set kcud=\n for wget_wch(); terminating
136 * *getn_wstr() with \n should work either way.
138 if (ch == KEY_DOWN || ch == KEY_ENTER) {
140 && win->_cury == win->_maxy
142 wechochar(win, (chtype) '\n');
145 if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
146 if (tmpstr > oldstr) {
147 tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
149 } else if (ch == KEY_EOL) {
150 while (tmpstr > oldstr) {
151 tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
156 } else if (maxlen >= 0 && tmpstr - oldstr >= maxlen) {
161 if (oldecho == TRUE) {
162 int oldy = win->_cury;
165 setcchar(&tmp, tmpstr - 1, A_NORMAL, 0, NULL);
166 if (wadd_wch(win, &tmp) == ERR) {
168 * We can't really use the lower-right corner for input,
169 * since it'll mess up bookkeeping for erases.
171 win->_flags &= ~_WRAPPED;
172 waddch(win, (chtype) ' ');
173 tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
175 } else if (win->_flags & _WRAPPED) {
177 * If the last waddch forced a wrap & scroll, adjust our
178 * reference point for erasures.
181 && oldy == win->_maxy
182 && win->_cury == win->_maxy) {
187 win->_flags &= ~_WRAPPED;
195 win->_flags &= ~_WRAPPED;
196 if (win->_cury < win->_maxy)
200 /* Restore with a single I/O call, to fix minor asymmetry between
206 SP->_cbreak = oldcbreak;
208 (void) _nc_set_tty_mode(&buf);
212 if (tmpstr == oldstr) {
213 *tmpstr++ = (wchar_t) WEOF;
219 T(("wgetn_wstr returns %s", _nc_viswbuf(oldstr)));