diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index 10273a94b834..7e06de861947 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -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. ./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/ttyunlock.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/types.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/ttyunlock.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/types.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/ttyunlock.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/types.3 comp-c-man .man ./usr/share/man/man3/tzalloc.3 comp-c-man .man diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index d65b0f44b29a..e626bcb3f903 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -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 .include @@ -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_window.3 subwin.3 curses_input.3 timeout.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_input.3 ungetch.3 curses_touch.3 untouchwin.3 \ curses_default_colors.3 use_default_colors.3 \ diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index d707d2922c0a..41c201ee9672 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -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 @@ -750,6 +750,7 @@ attr_t term_attrs(void); int touchline(WINDOW *, int, int); int touchoverlap(WINDOW *, WINDOW *); int touchwin(WINDOW *); +int typeahead(int); int ungetch(int); int untouchwin(WINDOW *); int use_default_colors(void); diff --git a/lib/libcurses/curses_private.h b/lib/libcurses/curses_private.h index ac511b9f6d6f..b09fafe986d9 100644 --- a/lib/libcurses/curses_private.h +++ b/lib/libcurses/curses_private.h @@ -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 @@ -253,6 +253,7 @@ struct __screen { wchar_t *unget_list; int unget_len, unget_pos; int filtered; + int checkfd; #ifdef HAVE_WCHAR #define MB_LEN_MAX 8 #define MAX_CBUF_SIZE MB_LEN_MAX diff --git a/lib/libcurses/curses_tty.3 b/lib/libcurses/curses_tty.3 index ec3de0a993f8..3e2b9a44ac9e 100644 --- a/lib/libcurses/curses_tty.3 +++ b/lib/libcurses/curses_tty.3 @@ -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 .\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" -.Dd December 29, 2016 +.Dd December 31, 2016 .Dt CURSES_TTY 3 .Os .Sh NAME @@ -65,6 +65,7 @@ .Nm nocbreak , .Nm raw , .Nm noraw , +.Nm typeahead , .Nm savetty , .Nm resetty .Nd curses terminal manipulation routines @@ -133,6 +134,8 @@ .Ft int .Fn noraw "void" .Ft int +.Fn typeahead "int filedes" +.Ft int .Fn savetty "void" .Ft int .Fn resetty "void" @@ -318,6 +321,33 @@ The function puts the terminal into Raw mode, no input character translation is done nor is signal character processing. .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 tty flags can be saved by calling .Fn savetty diff --git a/lib/libcurses/refresh.c b/lib/libcurses/refresh.c index f27499237f54..158b8b26bcaa 100644 --- a/lib/libcurses/refresh.c +++ b/lib/libcurses/refresh.c @@ -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 @@ -34,10 +34,11 @@ #if 0 static char sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94"; #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 /* not lint */ +#include #include #include @@ -586,6 +587,16 @@ doupdate(void) 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 { int i, j; @@ -716,6 +727,7 @@ doupdate(void) } } +cleanup: /* Don't leave the screen with attributes set. */ __unsetattr(0); #ifdef DEBUG diff --git a/lib/libcurses/screen.c b/lib/libcurses/screen.c index a9098735e546..cd09dc5b2335 100644 --- a/lib/libcurses/screen.c +++ b/lib/libcurses/screen.c @@ -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 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001"; #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 /* not lint */ @@ -137,6 +137,7 @@ newterm(char *type, FILE *outfd, FILE *infd) #endif new_screen->infd = infd; + new_screen->checkfd = fileno(infd); new_screen->outfd = outfd; new_screen->echoit = new_screen->nl = 1; new_screen->pfast = new_screen->rawmode = new_screen->noqch = 0; diff --git a/lib/libcurses/tty.c b/lib/libcurses/tty.c index 37bc9aec73a3..2c498d2f74bc 100644 --- a/lib/libcurses/tty.c +++ b/lib/libcurses/tty.c @@ -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 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95"; #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 /* not lint */ @@ -670,3 +670,11 @@ killwchar( wchar_t *ch ) return OK; #endif /* HAVE_WCHAR */ } + +int +typeahead(int filedes) +{ + + _cursesi_screen->checkfd = filedes; + return OK; +}