Keep pushed-back characters locally. Fixes problems where KEY_* symbols
are pushed back. Should fix the arrow keys part of PR pkg/37173. While we are here, make getch() and get_wch() check for resize immediately, instead of reading a key, checking for resize and then having to push-back the just read key.
This commit is contained in:
parent
28bae79b27
commit
7cc6075b0e
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: curses_private.h,v 1.40 2007/05/28 15:01:55 blymn Exp $ */
|
||||
/* $NetBSD: curses_private.h,v 1.41 2007/12/08 18:38:11 jdc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998-2000 Brett Lymn
|
||||
@ -304,6 +304,8 @@ struct __screen {
|
||||
int notty;
|
||||
int half_delay;
|
||||
int resized;
|
||||
wchar_t *unget_list;
|
||||
int unget_len, unget_pos;
|
||||
#ifdef HAVE_WCHAR
|
||||
#define MB_LEN_MAX 8
|
||||
#define MAX_CBUF_SIZE MB_LEN_MAX
|
||||
@ -369,6 +371,7 @@ void __cursesi_free_nsp(nschar_t *);
|
||||
void __cursesi_win_free_nsp(WINDOW *);
|
||||
void __cursesi_putnsp(nschar_t *, const int, const int);
|
||||
#endif /* HAVE_WCHAR */
|
||||
int __unget(wint_t);
|
||||
char *__longname(char *, char *); /* Original BSD version */
|
||||
int __mvcur(int, int, int, int, int);
|
||||
WINDOW *__newwin(SCREEN *, int, int, int, int, int);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: get_wch.c,v 1.4 2007/11/18 10:01:04 jdc Exp $ */
|
||||
/* $NetBSD: get_wch.c,v 1.5 2007/12/08 18:38:11 jdc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 The NetBSD Foundation Inc.
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: get_wch.c,v 1.4 2007/11/18 10:01:04 jdc Exp $");
|
||||
__RCSID("$NetBSD: get_wch.c,v 1.5 2007/12/08 18:38:11 jdc Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
@ -93,22 +93,14 @@ inkey(wchar_t *wc, int to, int delay)
|
||||
*end = &_cursesi_screen->cbuf_tail;
|
||||
char *inbuf = &_cursesi_screen->cbuf[ 0 ];
|
||||
|
||||
/* int ESCDELAY = 300;*/ /* Delay in ms between keys for esc seq's */
|
||||
ESCDELAY = 300;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "inkey (%p, %d, %d)\n", wc, to, delay);
|
||||
#endif
|
||||
for (;;) { /* loop until we get a complete key sequence */
|
||||
if (wstate == INKEY_NORM) {
|
||||
if (delay && __timeout(delay) == ERR)
|
||||
return ERR;
|
||||
c = getchar();
|
||||
if (_cursesi_screen->resized) {
|
||||
if (c != WEOF) /* was -1 */
|
||||
unget_wch(c);
|
||||
_cursesi_screen->resized = 0;
|
||||
clearerr(infd);
|
||||
*wc = KEY_RESIZE;
|
||||
return KEY_CODE_YES;
|
||||
}
|
||||
if (c == WEOF) {
|
||||
clearerr(infd);
|
||||
return ERR;
|
||||
@ -157,14 +149,6 @@ inkey(wchar_t *wc, int to, int delay)
|
||||
}
|
||||
|
||||
c = getchar();
|
||||
if (_cursesi_screen->resized) {
|
||||
if (c != -1)
|
||||
unget_wch(c);
|
||||
_cursesi_screen->resized = 0;
|
||||
clearerr(infd);
|
||||
*wc = KEY_RESIZE;
|
||||
return KEY_CODE_YES;
|
||||
}
|
||||
if (ferror(infd)) {
|
||||
clearerr(infd);
|
||||
return ERR;
|
||||
@ -215,14 +199,6 @@ inkey(wchar_t *wc, int to, int delay)
|
||||
}
|
||||
|
||||
c = getchar();
|
||||
if (_cursesi_screen->resized) {
|
||||
if (c != -1)
|
||||
unget_wch(c);
|
||||
_cursesi_screen->resized = 0;
|
||||
clearerr(infd);
|
||||
*wc = KEY_RESIZE;
|
||||
return KEY_CODE_YES;
|
||||
}
|
||||
if (ferror(infd)) {
|
||||
clearerr(infd);
|
||||
return ERR;
|
||||
@ -548,6 +524,25 @@ wget_wch(WINDOW *win, wint_t *ch)
|
||||
"__rawmode = %d, __nl = %d, flags = %#.4x\n",
|
||||
__echoit, __rawmode, _cursesi_screen->nl, win->flags);
|
||||
#endif
|
||||
if (_cursesi_screen->resized) {
|
||||
_cursesi_screen->resized = 0;
|
||||
*ch = KEY_RESIZE;
|
||||
return KEY_CODE_YES;
|
||||
}
|
||||
if (_cursesi_screen->unget_pos) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "wget_wch returning char at %d\n",
|
||||
_cursesi_screen->unget_pos);
|
||||
#endif
|
||||
_cursesi_screen->unget_pos--;
|
||||
*ch = _cursesi_screen->unget_list[_cursesi_screen->unget_pos];
|
||||
if (__echoit) {
|
||||
ws[0] = *ch, ws[1] = L'\0';
|
||||
setcchar(&wc, ws, win->wattr, 0, NULL);
|
||||
wadd_wch(win, &wc);
|
||||
}
|
||||
return KEY_CODE_YES;
|
||||
}
|
||||
if (__echoit && !__rawmode) {
|
||||
cbreak();
|
||||
weset = 1;
|
||||
@ -596,15 +591,6 @@ wget_wch(WINDOW *win, wint_t *ch)
|
||||
}
|
||||
|
||||
c = getwchar();
|
||||
if (_cursesi_screen->resized) {
|
||||
if (c != -1)
|
||||
unget_wch(c);
|
||||
_cursesi_screen->resized = 0;
|
||||
clearerr(infd);
|
||||
__restore_termios();
|
||||
*ch = KEY_RESIZE;
|
||||
return KEY_CODE_YES;
|
||||
}
|
||||
if (feof(infd)) {
|
||||
clearerr(infd);
|
||||
__restore_termios();
|
||||
@ -615,7 +601,7 @@ wget_wch(WINDOW *win, wint_t *ch)
|
||||
clearerr(infd);
|
||||
return ERR;
|
||||
} else {
|
||||
ret = c;
|
||||
ret = c;
|
||||
inp = c;
|
||||
}
|
||||
}
|
||||
@ -677,7 +663,5 @@ wget_wch(WINDOW *win, wint_t *ch)
|
||||
int
|
||||
unget_wch(const wchar_t c)
|
||||
{
|
||||
return
|
||||
( int )((ungetwc((wint_t)c, _cursesi_screen->infd) == WEOF) ?
|
||||
ERR : OK);
|
||||
return __unget((wint_t) c);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: getch.c,v 1.49 2007/08/28 12:28:18 blymn Exp $ */
|
||||
/* $NetBSD: getch.c,v 1.50 2007/12/08 18:38:11 jdc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: getch.c,v 1.49 2007/08/28 12:28:18 blymn Exp $");
|
||||
__RCSID("$NetBSD: getch.c,v 1.50 2007/12/08 18:38:11 jdc Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -208,8 +208,8 @@ int ESCDELAY = 300; /* Delay in ms between keys for esc seq's */
|
||||
/* Key buffer */
|
||||
#define INBUF_SZ 16 /* size of key buffer - must be larger than
|
||||
* longest multi-key sequence */
|
||||
static wchar_t inbuf[INBUF_SZ];
|
||||
static int start, end, working; /* pointers for manipulating inbuf data */
|
||||
static wchar_t inbuf[INBUF_SZ];
|
||||
static int start, end, working; /* pointers for manipulating inbuf data */
|
||||
|
||||
/* prototypes for private functions */
|
||||
static void add_key_sequence(SCREEN *screen, char *sequence, int key_type);
|
||||
@ -558,13 +558,6 @@ reread:
|
||||
if (delay && __timeout(delay) == ERR)
|
||||
return ERR;
|
||||
c = getchar();
|
||||
if (_cursesi_screen->resized) {
|
||||
if (c != -1)
|
||||
ungetch(c);
|
||||
_cursesi_screen->resized = 0;
|
||||
clearerr(infd);
|
||||
return KEY_RESIZE;
|
||||
}
|
||||
if (c == EOF) {
|
||||
clearerr(infd);
|
||||
return ERR;
|
||||
@ -607,13 +600,6 @@ reread:
|
||||
}
|
||||
|
||||
c = getchar();
|
||||
if (_cursesi_screen->resized) {
|
||||
if (c != -1)
|
||||
ungetch(c);
|
||||
_cursesi_screen->resized = 0;
|
||||
clearerr(infd);
|
||||
return KEY_RESIZE;
|
||||
}
|
||||
if (c == -1 || ferror(infd)) {
|
||||
clearerr(infd);
|
||||
return ERR;
|
||||
@ -822,6 +808,21 @@ wgetch(WINDOW *win)
|
||||
"__rawmode = %d, __nl = %d, flags = %#.4x\n",
|
||||
__echoit, __rawmode, _cursesi_screen->nl, win->flags);
|
||||
#endif
|
||||
if (_cursesi_screen->resized) {
|
||||
_cursesi_screen->resized = 0;
|
||||
return KEY_RESIZE;
|
||||
}
|
||||
if (_cursesi_screen->unget_pos) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "wgetch returning char at %d\n",
|
||||
_cursesi_screen->unget_pos);
|
||||
#endif
|
||||
_cursesi_screen->unget_pos--;
|
||||
c = _cursesi_screen->unget_list[_cursesi_screen->unget_pos];
|
||||
if (__echoit)
|
||||
waddch(win, (chtype) c);
|
||||
return c;
|
||||
}
|
||||
if (__echoit && !__rawmode) {
|
||||
cbreak();
|
||||
weset = 1;
|
||||
@ -871,14 +872,6 @@ wgetch(WINDOW *win)
|
||||
}
|
||||
|
||||
c = getchar();
|
||||
if (_cursesi_screen->resized) {
|
||||
if (c != -1)
|
||||
ungetch(c);
|
||||
_cursesi_screen->resized = 0;
|
||||
clearerr(infd);
|
||||
__restore_termios();
|
||||
return KEY_RESIZE;
|
||||
}
|
||||
if (feof(infd)) {
|
||||
clearerr(infd);
|
||||
__restore_termios();
|
||||
@ -930,5 +923,43 @@ wgetch(WINDOW *win)
|
||||
int
|
||||
ungetch(int c)
|
||||
{
|
||||
return ((ungetc(c, _cursesi_screen->infd) == EOF) ? ERR : OK);
|
||||
return __unget((wint_t) c);
|
||||
}
|
||||
|
||||
/*
|
||||
* __unget --
|
||||
* Do the work for ungetch() and unget_wch();
|
||||
*/
|
||||
int
|
||||
__unget(wint_t c)
|
||||
{
|
||||
wchar_t *p;
|
||||
int len;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "__unget(%x)\n", c);
|
||||
#endif
|
||||
if (_cursesi_screen->unget_pos >= _cursesi_screen->unget_len) {
|
||||
len = _cursesi_screen->unget_len + 32;
|
||||
if ((p = realloc(_cursesi_screen->unget_list,
|
||||
sizeof(wchar_t) * len)) == NULL) {
|
||||
/* Can't realloc(), so just lose the oldest entry */
|
||||
memmove(_cursesi_screen->unget_list,
|
||||
_cursesi_screen->unget_list + sizeof(wchar_t),
|
||||
_cursesi_screen->unget_len - 1);
|
||||
_cursesi_screen->unget_list[_cursesi_screen->unget_len
|
||||
- 1] = c;
|
||||
_cursesi_screen->unget_pos =
|
||||
_cursesi_screen->unget_len;
|
||||
return OK;
|
||||
} else {
|
||||
_cursesi_screen->unget_pos =
|
||||
_cursesi_screen->unget_len;
|
||||
_cursesi_screen->unget_len = len;
|
||||
_cursesi_screen->unget_list = p;
|
||||
}
|
||||
}
|
||||
_cursesi_screen->unget_list[_cursesi_screen->unget_pos] = c;
|
||||
_cursesi_screen->unget_pos++;
|
||||
return OK;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: screen.c,v 1.20 2007/05/28 15:01:57 blymn Exp $ */
|
||||
/* $NetBSD: screen.c,v 1.21 2007/12/08 18:38:11 jdc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
@ -34,7 +34,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001";
|
||||
#else
|
||||
__RCSID("$NetBSD: screen.c,v 1.20 2007/05/28 15:01:57 blymn Exp $");
|
||||
__RCSID("$NetBSD: screen.c,v 1.21 2007/12/08 18:38:11 jdc Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -140,6 +140,13 @@ newterm(char *type, FILE *outfd, FILE *infd)
|
||||
new_screen->notty = FALSE;
|
||||
new_screen->half_delay = FALSE;
|
||||
new_screen->resized = 0;
|
||||
new_screen->unget_len = 32;
|
||||
|
||||
if ((new_screen->unget_list =
|
||||
malloc(sizeof(wchar_t) * new_screen->unget_len)) == NULL) {
|
||||
goto error_exit;
|
||||
}
|
||||
new_screen->unget_pos = 0;
|
||||
|
||||
if (_cursesi_gettmode(new_screen) == ERR)
|
||||
goto error_exit;
|
||||
|
Loading…
Reference in New Issue
Block a user