Implement POSIX Curses typeahead function.

This commit is contained in:
roy 2016-12-31 22:47:01 +00:00
parent 64f28c9b37
commit a663bc11be
8 changed files with 70 additions and 13 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.2086 2016/12/31 17:46:35 roy Exp $ # $NetBSD: mi,v 1.2087 2016/12/31 22:47:01 roy Exp $
# #
# Note: don't delete entries from here - mark them as "obsolete" instead. # Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root ./etc/mtree/set.comp comp-sys-root
@ -9467,6 +9467,7 @@
./usr/share/man/cat3/ttyslot.0 comp-c-catman .cat ./usr/share/man/cat3/ttyslot.0 comp-c-catman .cat
./usr/share/man/cat3/ttyunlock.0 comp-c-catman .cat ./usr/share/man/cat3/ttyunlock.0 comp-c-catman .cat
./usr/share/man/cat3/twalk.0 comp-c-catman .cat ./usr/share/man/cat3/twalk.0 comp-c-catman .cat
./usr/share/man/cat3/typeahead.0 comp-c-catman .cat
./usr/share/man/cat3/typeof.0 comp-c-catman .cat ./usr/share/man/cat3/typeof.0 comp-c-catman .cat
./usr/share/man/cat3/types.0 comp-c-catman .cat ./usr/share/man/cat3/types.0 comp-c-catman .cat
./usr/share/man/cat3/tzalloc.0 comp-c-catman .cat ./usr/share/man/cat3/tzalloc.0 comp-c-catman .cat
@ -16736,6 +16737,7 @@
./usr/share/man/html3/ttyslot.html comp-c-htmlman html ./usr/share/man/html3/ttyslot.html comp-c-htmlman html
./usr/share/man/html3/ttyunlock.html comp-c-htmlman html ./usr/share/man/html3/ttyunlock.html comp-c-htmlman html
./usr/share/man/html3/twalk.html comp-c-htmlman html ./usr/share/man/html3/twalk.html comp-c-htmlman html
./usr/share/man/html3/typeahead.html comp-c-htmlman html
./usr/share/man/html3/typeof.html comp-c-htmlman html ./usr/share/man/html3/typeof.html comp-c-htmlman html
./usr/share/man/html3/types.html comp-c-htmlman html ./usr/share/man/html3/types.html comp-c-htmlman html
./usr/share/man/html3/tzalloc.html comp-c-htmlman html ./usr/share/man/html3/tzalloc.html comp-c-htmlman html
@ -24068,6 +24070,7 @@
./usr/share/man/man3/ttyslot.3 comp-c-man .man ./usr/share/man/man3/ttyslot.3 comp-c-man .man
./usr/share/man/man3/ttyunlock.3 comp-c-man .man ./usr/share/man/man3/ttyunlock.3 comp-c-man .man
./usr/share/man/man3/twalk.3 comp-c-man .man ./usr/share/man/man3/twalk.3 comp-c-man .man
./usr/share/man/man3/typeahead.3 comp-c-man .man
./usr/share/man/man3/typeof.3 comp-c-man .man ./usr/share/man/man3/typeof.3 comp-c-man .man
./usr/share/man/man3/types.3 comp-c-man .man ./usr/share/man/man3/types.3 comp-c-man .man
./usr/share/man/man3/tzalloc.3 comp-c-man .man ./usr/share/man/man3/tzalloc.3 comp-c-man .man

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.74 2016/12/31 17:46:35 roy Exp $ # $NetBSD: Makefile,v 1.75 2016/12/31 22:47:01 roy Exp $
# @(#)Makefile 8.2 (Berkeley) 1/2/94 # @(#)Makefile 8.2 (Berkeley) 1/2/94
.include <bsd.own.mk> .include <bsd.own.mk>
@ -149,7 +149,8 @@ MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.3 \
curses_color.3 start_color.3 curses_pad.3 subpad.3 \ curses_color.3 start_color.3 curses_pad.3 subpad.3 \
curses_window.3 subwin.3 curses_input.3 timeout.3 \ curses_window.3 subwin.3 curses_input.3 timeout.3 \
curses_touch.3 touchline.3 curses_touch.3 touchoverlap.3 \ curses_touch.3 touchline.3 curses_touch.3 touchoverlap.3 \
curses_touch.3 touchwin.3 curses_print.3 unctrl.3 \ curses_touch.3 touchwin.3 curses_tty.3 typeahead.3 \
curses_print.3 unctrl.3 \
curses_underscore.3 underend.3 curses_underscore.3 underscore.3 \ curses_underscore.3 underend.3 curses_underscore.3 underscore.3 \
curses_input.3 ungetch.3 curses_touch.3 untouchwin.3 \ curses_input.3 ungetch.3 curses_touch.3 untouchwin.3 \
curses_default_colors.3 use_default_colors.3 \ curses_default_colors.3 use_default_colors.3 \

View File

@ -1,4 +1,4 @@
/* $NetBSD: curses.h,v 1.110 2016/12/31 17:46:35 roy Exp $ */ /* $NetBSD: curses.h,v 1.111 2016/12/31 22:47:01 roy Exp $ */
/* /*
* Copyright (c) 1981, 1993, 1994 * Copyright (c) 1981, 1993, 1994
@ -750,6 +750,7 @@ attr_t term_attrs(void);
int touchline(WINDOW *, int, int); int touchline(WINDOW *, int, int);
int touchoverlap(WINDOW *, WINDOW *); int touchoverlap(WINDOW *, WINDOW *);
int touchwin(WINDOW *); int touchwin(WINDOW *);
int typeahead(int);
int ungetch(int); int ungetch(int);
int untouchwin(WINDOW *); int untouchwin(WINDOW *);
int use_default_colors(void); int use_default_colors(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: curses_private.h,v 1.52 2016/12/30 22:38:38 roy Exp $ */ /* $NetBSD: curses_private.h,v 1.53 2016/12/31 22:47:01 roy Exp $ */
/*- /*-
* Copyright (c) 1998-2000 Brett Lymn * Copyright (c) 1998-2000 Brett Lymn
@ -253,6 +253,7 @@ struct __screen {
wchar_t *unget_list; wchar_t *unget_list;
int unget_len, unget_pos; int unget_len, unget_pos;
int filtered; int filtered;
int checkfd;
#ifdef HAVE_WCHAR #ifdef HAVE_WCHAR
#define MB_LEN_MAX 8 #define MB_LEN_MAX 8
#define MAX_CBUF_SIZE MB_LEN_MAX #define MAX_CBUF_SIZE MB_LEN_MAX

View File

@ -1,4 +1,4 @@
.\" $NetBSD: curses_tty.3,v 1.9 2016/12/29 23:50:59 wiz Exp $ .\" $NetBSD: curses_tty.3,v 1.10 2016/12/31 22:47:01 roy Exp $
.\" .\"
.\" Copyright (c) 2002 .\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) .\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
@ -30,7 +30,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" .\"
.Dd December 29, 2016 .Dd December 31, 2016
.Dt CURSES_TTY 3 .Dt CURSES_TTY 3
.Os .Os
.Sh NAME .Sh NAME
@ -65,6 +65,7 @@
.Nm nocbreak , .Nm nocbreak ,
.Nm raw , .Nm raw ,
.Nm noraw , .Nm noraw ,
.Nm typeahead ,
.Nm savetty , .Nm savetty ,
.Nm resetty .Nm resetty
.Nd curses terminal manipulation routines .Nd curses terminal manipulation routines
@ -133,6 +134,8 @@
.Ft int .Ft int
.Fn noraw "void" .Fn noraw "void"
.Ft int .Ft int
.Fn typeahead "int filedes"
.Ft int
.Fn savetty "void" .Fn savetty "void"
.Ft int .Ft int
.Fn resetty "void" .Fn resetty "void"
@ -318,6 +321,33 @@ The
function puts the terminal into Raw mode, no input character function puts the terminal into Raw mode, no input character
translation is done nor is signal character processing. translation is done nor is signal character processing.
.Pp .Pp
The
.Fn typeahead
function controls the detection of typeahead during a refresh based on the
value of
.Va filedes :
.Bl -bullet -compact
.It
If
.Ar filedes
is a valid file descriptor, typeahead is enabled during refresh;
Curses periodically checks
.Ar filedes
for input and aborts the refresh if any character is available.
(This is the initial setting and the typeahead file descriptor corresponds
to the input file associated with the screen created by
.Fn initscr
or
.Fn newterm .
The value of
.Ar filedes
need not be the file descriptor on which the refresh is occurring.
.It
If
.Ar filedes
is \-1, Curses does not check for typeahead during refresh.
.El
.Pp
The terminal The terminal
tty flags can be saved by calling tty flags can be saved by calling
.Fn savetty .Fn savetty

View File

@ -1,4 +1,4 @@
/* $NetBSD: refresh.c,v 1.80 2016/01/10 08:11:06 jdc Exp $ */ /* $NetBSD: refresh.c,v 1.81 2016/12/31 22:47:01 roy Exp $ */
/* /*
* Copyright (c) 1981, 1993, 1994 * Copyright (c) 1981, 1993, 1994
@ -34,10 +34,11 @@
#if 0 #if 0
static char sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94"; static char sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94";
#else #else
__RCSID("$NetBSD: refresh.c,v 1.80 2016/01/10 08:11:06 jdc Exp $"); __RCSID("$NetBSD: refresh.c,v 1.81 2016/12/31 22:47:01 roy Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
#include <poll.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -586,6 +587,16 @@ doupdate(void)
quickch(); quickch();
} }
if (_cursesi_screen->checkfd != -1) {
struct pollfd fds[1];
/* If we have input, abort the update. */
fds[0].fd = _cursesi_screen->checkfd;
fds[0].events = POLLIN;
if (poll(fds, 1, 0) > 0)
goto cleanup;
}
#ifdef DEBUG #ifdef DEBUG
{ {
int i, j; int i, j;
@ -716,6 +727,7 @@ doupdate(void)
} }
} }
cleanup:
/* Don't leave the screen with attributes set. */ /* Don't leave the screen with attributes set. */
__unsetattr(0); __unsetattr(0);
#ifdef DEBUG #ifdef DEBUG

View File

@ -1,4 +1,4 @@
/* $NetBSD: screen.c,v 1.25 2016/12/30 22:38:38 roy Exp $ */ /* $NetBSD: screen.c,v 1.26 2016/12/31 22:47:01 roy Exp $ */
/* /*
* Copyright (c) 1981, 1993, 1994 * Copyright (c) 1981, 1993, 1994
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001"; static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001";
#else #else
__RCSID("$NetBSD: screen.c,v 1.25 2016/12/30 22:38:38 roy Exp $"); __RCSID("$NetBSD: screen.c,v 1.26 2016/12/31 22:47:01 roy Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -137,6 +137,7 @@ newterm(char *type, FILE *outfd, FILE *infd)
#endif #endif
new_screen->infd = infd; new_screen->infd = infd;
new_screen->checkfd = fileno(infd);
new_screen->outfd = outfd; new_screen->outfd = outfd;
new_screen->echoit = new_screen->nl = 1; new_screen->echoit = new_screen->nl = 1;
new_screen->pfast = new_screen->rawmode = new_screen->noqch = 0; new_screen->pfast = new_screen->rawmode = new_screen->noqch = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: tty.c,v 1.44 2016/12/12 04:20:31 christos Exp $ */ /* $NetBSD: tty.c,v 1.45 2016/12/31 22:47:01 roy Exp $ */
/*- /*-
* Copyright (c) 1992, 1993, 1994 * Copyright (c) 1992, 1993, 1994
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95"; static char sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95";
#else #else
__RCSID("$NetBSD: tty.c,v 1.44 2016/12/12 04:20:31 christos Exp $"); __RCSID("$NetBSD: tty.c,v 1.45 2016/12/31 22:47:01 roy Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -670,3 +670,11 @@ killwchar( wchar_t *ch )
return OK; return OK;
#endif /* HAVE_WCHAR */ #endif /* HAVE_WCHAR */
} }
int
typeahead(int filedes)
{
_cursesi_screen->checkfd = filedes;
return OK;
}