Module Name: src Committed By: roy Date: Sat Dec 31 22:47:01 UTC 2016
Modified Files: src/distrib/sets/lists/comp: mi src/lib/libcurses: Makefile curses.h curses_private.h curses_tty.3 refresh.c screen.c tty.c Log Message: Implement POSIX Curses typeahead function. To generate a diff of this commit: cvs rdiff -u -r1.2086 -r1.2087 src/distrib/sets/lists/comp/mi cvs rdiff -u -r1.74 -r1.75 src/lib/libcurses/Makefile cvs rdiff -u -r1.110 -r1.111 src/lib/libcurses/curses.h cvs rdiff -u -r1.52 -r1.53 src/lib/libcurses/curses_private.h cvs rdiff -u -r1.9 -r1.10 src/lib/libcurses/curses_tty.3 cvs rdiff -u -r1.80 -r1.81 src/lib/libcurses/refresh.c cvs rdiff -u -r1.25 -r1.26 src/lib/libcurses/screen.c cvs rdiff -u -r1.44 -r1.45 src/lib/libcurses/tty.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/comp/mi diff -u src/distrib/sets/lists/comp/mi:1.2086 src/distrib/sets/lists/comp/mi:1.2087 --- src/distrib/sets/lists/comp/mi:1.2086 Sat Dec 31 17:46:35 2016 +++ src/distrib/sets/lists/comp/mi Sat Dec 31 22:47:01 2016 @@ -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 Index: src/lib/libcurses/Makefile diff -u src/lib/libcurses/Makefile:1.74 src/lib/libcurses/Makefile:1.75 --- src/lib/libcurses/Makefile:1.74 Sat Dec 31 17:46:35 2016 +++ src/lib/libcurses/Makefile Sat Dec 31 22:47:01 2016 @@ -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 <bsd.own.mk> @@ -149,7 +149,8 @@ MLINKS+= curses_addch.3 addch.3 curses_a 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 \ Index: src/lib/libcurses/curses.h diff -u src/lib/libcurses/curses.h:1.110 src/lib/libcurses/curses.h:1.111 --- src/lib/libcurses/curses.h:1.110 Sat Dec 31 17:46:35 2016 +++ src/lib/libcurses/curses.h Sat Dec 31 22:47:01 2016 @@ -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); Index: src/lib/libcurses/curses_private.h diff -u src/lib/libcurses/curses_private.h:1.52 src/lib/libcurses/curses_private.h:1.53 --- src/lib/libcurses/curses_private.h:1.52 Fri Dec 30 22:38:38 2016 +++ src/lib/libcurses/curses_private.h Sat Dec 31 22:47:01 2016 @@ -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 Index: src/lib/libcurses/curses_tty.3 diff -u src/lib/libcurses/curses_tty.3:1.9 src/lib/libcurses/curses_tty.3:1.10 --- src/lib/libcurses/curses_tty.3:1.9 Thu Dec 29 23:50:59 2016 +++ src/lib/libcurses/curses_tty.3 Sat Dec 31 22:47:01 2016 @@ -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 (bl...@netbsd.org, brett_l...@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 Index: src/lib/libcurses/refresh.c diff -u src/lib/libcurses/refresh.c:1.80 src/lib/libcurses/refresh.c:1.81 --- src/lib/libcurses/refresh.c:1.80 Sun Jan 10 08:11:06 2016 +++ src/lib/libcurses/refresh.c Sat Dec 31 22:47:01 2016 @@ -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 <poll.h> #include <stdlib.h> #include <string.h> @@ -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 Index: src/lib/libcurses/screen.c diff -u src/lib/libcurses/screen.c:1.25 src/lib/libcurses/screen.c:1.26 --- src/lib/libcurses/screen.c:1.25 Fri Dec 30 22:38:38 2016 +++ src/lib/libcurses/screen.c Sat Dec 31 22:47:01 2016 @@ -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 *i #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; Index: src/lib/libcurses/tty.c diff -u src/lib/libcurses/tty.c:1.44 src/lib/libcurses/tty.c:1.45 --- src/lib/libcurses/tty.c:1.44 Mon Dec 12 04:20:31 2016 +++ src/lib/libcurses/tty.c Sat Dec 31 22:47:01 2016 @@ -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; +}