Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Implement POSIX Curses typeahead function.



details:   https://anonhg.NetBSD.org/src/rev/21f2a09986df
branches:  trunk
changeset: 820143:21f2a09986df
user:      roy <roy%NetBSD.org@localhost>
date:      Sat Dec 31 22:47:01 2016 +0000

description:
Implement POSIX Curses typeahead function.

diffstat:

 distrib/sets/lists/comp/mi     |   5 ++++-
 lib/libcurses/Makefile         |   5 +++--
 lib/libcurses/curses.h         |   3 ++-
 lib/libcurses/curses_private.h |   3 ++-
 lib/libcurses/curses_tty.3     |  34 ++++++++++++++++++++++++++++++++--
 lib/libcurses/refresh.c        |  16 ++++++++++++++--
 lib/libcurses/screen.c         |   5 +++--
 lib/libcurses/tty.c            |  12 ++++++++++--
 8 files changed, 70 insertions(+), 13 deletions(-)

diffs (258 lines):

diff -r e89719ef53b0 -r 21f2a09986df distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sat Dec 31 22:46:46 2016 +0000
+++ b/distrib/sets/lists/comp/mi        Sat Dec 31 22:47:01 2016 +0000
@@ -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 -r e89719ef53b0 -r 21f2a09986df lib/libcurses/Makefile
--- a/lib/libcurses/Makefile    Sat Dec 31 22:46:46 2016 +0000
+++ b/lib/libcurses/Makefile    Sat Dec 31 22:47:01 2016 +0000
@@ -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 @@
         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 -r e89719ef53b0 -r 21f2a09986df lib/libcurses/curses.h
--- a/lib/libcurses/curses.h    Sat Dec 31 22:46:46 2016 +0000
+++ b/lib/libcurses/curses.h    Sat Dec 31 22:47:01 2016 +0000
@@ -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 @@
 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 -r e89719ef53b0 -r 21f2a09986df lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h    Sat Dec 31 22:46:46 2016 +0000
+++ b/lib/libcurses/curses_private.h    Sat Dec 31 22:47:01 2016 +0000
@@ -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 @@
        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 -r e89719ef53b0 -r 21f2a09986df lib/libcurses/curses_tty.3
--- a/lib/libcurses/curses_tty.3        Sat Dec 31 22:46:46 2016 +0000
+++ b/lib/libcurses/curses_tty.3        Sat Dec 31 22:47:01 2016 +0000
@@ -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@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -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 @@
 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 -r e89719ef53b0 -r 21f2a09986df lib/libcurses/refresh.c
--- a/lib/libcurses/refresh.c   Sat Dec 31 22:46:46 2016 +0000
+++ b/lib/libcurses/refresh.c   Sat Dec 31 22:47:01 2016 +0000
@@ -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 @@
                        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 @@
                }
        }
 
+cleanup:
        /* Don't leave the screen with attributes set. */
        __unsetattr(0);
 #ifdef DEBUG
diff -r e89719ef53b0 -r 21f2a09986df lib/libcurses/screen.c
--- a/lib/libcurses/screen.c    Sat Dec 31 22:46:46 2016 +0000
+++ b/lib/libcurses/screen.c    Sat Dec 31 22:47:01 2016 +0000
@@ -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 @@
 #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 -r e89719ef53b0 -r 21f2a09986df lib/libcurses/tty.c
--- a/lib/libcurses/tty.c       Sat Dec 31 22:46:46 2016 +0000
+++ b/lib/libcurses/tty.c       Sat Dec 31 22:47:01 2016 +0000
@@ -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 @@
        return OK;
 #endif /* HAVE_WCHAR */
 }
+
+int
+typeahead(int filedes)
+{
+
+       _cursesi_screen->checkfd = filedes;
+       return OK;
+}



Home | Main Index | Thread Index | Old Index