diff options
author | 1997-11-26 04:01:02 +0000 | |
---|---|---|
committer | 1997-11-26 04:01:02 +0000 | |
commit | 010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b (patch) | |
tree | 5ee5e7213ad9b412a927de7effdcb7c8ce4b489e /lib/libcurses/lib_getstr.c | |
parent | libform from ncurses 4.1. Post 4.1 patches to be applied in a separate commit. (diff) | |
download | wireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.tar.xz wireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.zip |
ncurses 4.1 + changes to work with our terminfo libs (instead of
the ncurses ones). Changes are #ifdef EXTERN_TERMINFO.
Post 4.1 patches will be applied in a separate commit.
Diffstat (limited to 'lib/libcurses/lib_getstr.c')
-rw-r--r-- | lib/libcurses/lib_getstr.c | 123 |
1 files changed, 77 insertions, 46 deletions
diff --git a/lib/libcurses/lib_getstr.c b/lib/libcurses/lib_getstr.c index 5f4dbcd2b7c..55248e20e6b 100644 --- a/lib/libcurses/lib_getstr.c +++ b/lib/libcurses/lib_getstr.c @@ -27,19 +27,49 @@ ** */ -#include "curses.priv.h" -#include "unctrl.h" -#include <string.h> +#include <curses.priv.h> +#include <term.h> + +MODULE_ID("Id: lib_getstr.c,v 1.11 1997/02/01 23:22:54 tom Exp $") + +/* + * This wipes out the last character, no matter whether it was a tab, control + * or other character, and handles reverse wraparound. + */ +static char *WipeOut(WINDOW *win, int y, int x, char *first, char *last, bool echoed) +{ + if (last > first) { + *--last = '\0'; + if (echoed) { + int y1 = win->_cury; + int x1 = win->_curx; + + wmove(win, y, x); + waddstr(win, first); + getyx(win, y, x); + while (win->_cury < y1 + || (win->_cury == y1 && win->_curx < x1)) + waddch(win, ' '); + + wmove(win, y, x); + } + } + return last; +} int wgetnstr(WINDOW *win, char *str, int maxlen) { +TTY buf; bool oldnl, oldecho, oldraw, oldcbreak, oldkeypad; char erasec; char killc; char *oldstr; int ch; - - T(("wgetnstr(%p,%p, %d) called", win, str, maxlen)); +int y, x; + + T((T_CALLED("wgetnstr(%p,%p, %d)"), win, str, maxlen)); + + GET_TTY(cur_term->Filedes, &buf); oldnl = SP->_nl; oldecho = SP->_echo; @@ -56,76 +86,77 @@ int ch; killc = killchar(); oldstr = str; + getyx(win, y, x); if (is_wintouched(win) || (win->_flags & _HASMOVED)) wrefresh(win); while ((ch = wgetch(win)) != ERR) { - /* + /* * Some terminals (the Wyse-50 is the most common) generate * a \n from the down-arrow key. With this logic, it's the * user's choice whether to set kcud=\n for wgetch(); * terminating *getstr() with \n should work either way. */ - if (ch == '\n' || ch == '\r' || ch == KEY_DOWN) + if (ch == '\n' + || ch == '\r' + || ch == KEY_DOWN + || ch == KEY_ENTER) break; - if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { + if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) { if (str > oldstr) { - str--; - if (oldecho == TRUE) - _nc_backspace(win); + str = WipeOut(win, y, x, oldstr, str, oldecho); } - } else if (ch == killc) { + } else if (ch == killc) { while (str > oldstr) { - str--; - if (oldecho == TRUE) - _nc_backspace(win); + str = WipeOut(win, y, x, oldstr, str, oldecho); } } else if (ch >= KEY_MIN || (maxlen >= 0 && str - oldstr >= maxlen)) { - beep(); + beep(); } else { - if (oldecho == TRUE) { - char *glyph = unctrl(ch); - - mvwaddstr(curscr, win->_begy + win->_cury, - win->_begx + win->_curx, glyph); - waddstr(win, glyph); - _nc_outstr(glyph); - SP->_curscol += strlen(glyph); - } *str++ = ch; - } + if (oldecho == TRUE) { + if (waddch(win, ch) == ERR) { + /* + * We can't really use the lower-right + * corner for input, since it'll mess + * up bookkeeping for erases. + */ + win->_flags &= ~_WRAPPED; + waddch(win, ' '); + str = WipeOut(win, y, x, oldstr, str, oldecho); + continue; + } + wrefresh(win); + } + } } - win->_curx = 0; - win->_flags &= ~_NEED_WRAP; - if (win->_cury < win->_maxy) - win->_cury++; + win->_curx = 0; + win->_flags &= ~_WRAPPED; + if (win->_cury < win->_maxy) + win->_cury++; wrefresh(win); - if (oldnl == FALSE) - nonl(); + /* Restore with a single I/O call, to fix minor asymmetry between + * raw/noraw, etc. + */ + SP->_nl = oldnl; + SP->_echo = oldecho; + SP->_raw = oldraw; + SP->_cbreak = oldcbreak; - if (oldecho == TRUE) - echo(); - - if (oldraw == TRUE) - raw(); - - if (oldcbreak == FALSE) - nocbreak(); + SET_TTY(cur_term->Filedes, &buf); if (oldkeypad == FALSE) keypad(win, FALSE); - if (ch == ERR) { - *str = '\0'; - return ERR; - } *str = '\0'; + if (ch == ERR) + returnCode(ERR); - T(("wgetnstr returns \"%s\"", _nc_visbuf(oldstr))); + T(("wgetnstr returns %s", _nc_visbuf(oldstr))); - return(OK); + returnCode(OK); } |