X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=ncurses%2Flib_getstr.c;h=33a637ed65610e29e1e2fba1c09bf4f027956821;hb=661078ddbde3ce0f3b06e95642fbb9b5fef7dca1;hp=aaed18734bb3066fdec68d124a99e47a1f9afda4;hpb=3a9b6a3bf0269231bef7de74757a910dedd04e0c;p=ncurses.git diff --git a/ncurses/lib_getstr.c b/ncurses/lib_getstr.c index aaed1873..33a637ed 100644 --- a/ncurses/lib_getstr.c +++ b/ncurses/lib_getstr.c @@ -1,23 +1,35 @@ - -/*************************************************************************** -* COPYRIGHT NOTICE * -**************************************************************************** -* ncurses is copyright (C) 1992-1995 * -* Zeyd M. Ben-Halim * -* zmbenhal@netcom.com * -* Eric S. Raymond * -* esr@snark.thyrsus.com * -* * -* Permission is hereby granted to reproduce and distribute ncurses * -* by any means and for any fee, whether alone or as part of a * -* larger distribution, in source or in binary form, PROVIDED * -* this notice is included with any such distribution, and is not * -* removed from any of its header files. Mention of ncurses in any * -* applications linked with it is highly appreciated. * -* * -* ncurses comes AS IS with no warranty, implied or expressed. * -* * -***************************************************************************/ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Zeyd M. Ben-Halim 1992,1995 * + * and: Eric S. Raymond * + ****************************************************************************/ /* @@ -30,7 +42,7 @@ #include #include -MODULE_ID("$Id: lib_getstr.c,v 1.11 1997/02/01 23:22:54 tom Exp $") +MODULE_ID("$Id: lib_getstr.c,v 1.19 1998/02/11 12:13:53 tom Exp $") /* * This wipes out the last character, no matter whether it was a tab, control @@ -60,7 +72,7 @@ static char *WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool ec int wgetnstr(WINDOW *win, char *str, int maxlen) { TTY buf; -bool oldnl, oldecho, oldraw, oldcbreak, oldkeypad; +bool oldnl, oldecho, oldraw, oldcbreak; char erasec; char killc; char *oldstr; @@ -69,18 +81,19 @@ int y, x; T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen)); - GET_TTY(cur_term->Filedes, &buf); + if (!win) + returnCode(ERR); + + _nc_get_curterm(&buf); oldnl = SP->_nl; oldecho = SP->_echo; oldraw = SP->_raw; oldcbreak = SP->_cbreak; - oldkeypad = win->_use_keypad; nl(); noecho(); noraw(); cbreak(); - keypad(win, TRUE); erasec = erasechar(); killc = killchar(); @@ -101,8 +114,13 @@ int y, x; if (ch == '\n' || ch == '\r' || ch == KEY_DOWN - || ch == KEY_ENTER) + || ch == KEY_ENTER) { + if (oldecho == TRUE + && win->_cury == win->_maxy + && win->_scroll) + wechochar(win, '\n'); break; + } if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (str > oldstr) { str = WipeOut(win, y, x, oldstr, str, oldecho); @@ -117,6 +135,7 @@ int y, x; } else { *str++ = ch; if (oldecho == TRUE) { + int oldy = win->_cury; if (waddch(win, ch) == ERR) { /* * We can't really use the lower-right @@ -127,6 +146,20 @@ int y, x; waddch(win, ' '); str = WipeOut(win, y, x, oldstr, str, oldecho); continue; + } else if (win->_flags & _WRAPPED) { + /* + * If the last waddch forced a wrap & + * scroll, adjust our reference point + * for erasures. + */ + if (win->_scroll + && oldy == win->_maxy + && win->_cury == win->_maxy) { + if (--y <= 0) { + y = 0; + } + } + win->_flags &= ~_WRAPPED; } wrefresh(win); } @@ -147,10 +180,7 @@ int y, x; SP->_raw = oldraw; SP->_cbreak = oldcbreak; - SET_TTY(cur_term->Filedes, &buf); - - if (oldkeypad == FALSE) - keypad(win, FALSE); + _nc_set_curterm(&buf); *str = '\0'; if (ch == ERR)