Source-Changes-HG archive

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

[src/trunk]: src Implement ncurses extensions is_leaveok and is_keypad.



details:   https://anonhg.NetBSD.org/src/rev/80af80089b35
branches:  trunk
changeset: 820135:80af80089b35
user:      roy <roy%NetBSD.org@localhost>
date:      Sat Dec 31 13:50:16 2016 +0000

description:
Implement ncurses extensions is_leaveok and is_keypad.

The former allows the ncurses (and pdcurses) macros getsyx and setsyx
to be implemented, which is needed by a surprising number of applications.

The latter is needed for Python curses support so it doesn't have to dive
into ncurses window structure.

diffstat:

 distrib/sets/lists/comp/mi     |  14 +++++++++++++-
 lib/libcurses/Makefile         |  10 +++++++---
 lib/libcurses/curses.h         |  24 +++++++++++++++++++++++-
 lib/libcurses/curses_cursor.3  |  42 ++++++++++++++++++++++++++++++++++++++++--
 lib/libcurses/curses_pad.3     |  16 ++++++++++++++--
 lib/libcurses/curses_refresh.3 |  17 +++++++++++++++--
 lib/libcurses/keypad.c         |  15 +++++++++++++--
 lib/libcurses/leaveok.c        |  15 +++++++++++++--
 8 files changed, 138 insertions(+), 15 deletions(-)

diffs (truncated from 431 to 300 lines):

diff -r 5cdd49e9ec01 -r 80af80089b35 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sat Dec 31 11:51:20 2016 +0000
+++ b/distrib/sets/lists/comp/mi        Sat Dec 31 13:50:16 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2084 2016/12/30 22:38:38 roy Exp $
+#      $NetBSD: mi,v 1.2085 2016/12/31 13:50:16 roy Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -6663,6 +6663,7 @@
 ./usr/share/man/cat3/getskeyprompt.0           comp-c-catman           skey,.cat
 ./usr/share/man/cat3/getstr.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/getsubopt.0               comp-c-catman           .cat
+./usr/share/man/cat3/getsyx.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/gettext.0                 comp-c-catman           .cat
 ./usr/share/man/cat3/gettmode.0                        comp-c-catman           .cat
 ./usr/share/man/cat3/getttyent.0               comp-c-catman           .cat
@@ -6873,6 +6874,8 @@
 ./usr/share/man/cat3/ipsec_strerror.0          comp-c-catman           .cat
 ./usr/share/man/cat3/iruserok.0                        comp-c-catman           .cat
 ./usr/share/man/cat3/iruserok_sa.0             comp-c-catman           .cat
+./usr/share/man/cat3/is_keypad.0               comp-c-catman           .cat
+./usr/share/man/cat3/is_leaveok.0              comp-c-catman           .cat
 ./usr/share/man/cat3/is_linetouched.0          comp-c-catman           .cat
 ./usr/share/man/cat3/is_wintouched.0           comp-c-catman           .cat
 ./usr/share/man/cat3/isalnum.0                 comp-c-catman           .cat
@@ -8920,6 +8923,7 @@
 ./usr/share/man/cat3/setscrreg.0               comp-c-catman           .cat
 ./usr/share/man/cat3/setservent.0              comp-c-catman           .cat
 ./usr/share/man/cat3/setstate.0                        comp-c-catman           .cat
+./usr/share/man/cat3/setsyx.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/setterm.0                 comp-c-catman           .cat
 ./usr/share/man/cat3/setttyent.0               comp-c-catman           .cat
 ./usr/share/man/cat3/setttyentpath.0           comp-c-catman           .cat
@@ -14011,6 +14015,7 @@
 ./usr/share/man/html3/getutmpx.html            comp-c-htmlman          html
 ./usr/share/man/html3/getutxent.html           comp-c-htmlman          html
 ./usr/share/man/html3/getutxid.html            comp-c-htmlman          html
+./usr/share/man/html3/getsyx.html              comp-c-htmlman          html
 ./usr/share/man/html3/getutxline.html          comp-c-htmlman          html
 ./usr/share/man/html3/getw.html                        comp-c-htmlman          html
 ./usr/share/man/html3/getwc.html               comp-c-htmlman          html
@@ -14212,6 +14217,8 @@
 ./usr/share/man/html3/ipsec_strerror.html      comp-c-htmlman          html
 ./usr/share/man/html3/iruserok.html            comp-c-htmlman          html
 ./usr/share/man/html3/iruserok_sa.html         comp-c-htmlman          html
+./usr/share/man/html3/is_keypad.html           comp-c-htmlman          html
+./usr/share/man/html3/is_leaveok.html          comp-c-htmlman          html
 ./usr/share/man/html3/is_linetouched.html      comp-c-htmlman          html
 ./usr/share/man/html3/is_wintouched.html       comp-c-htmlman          html
 ./usr/share/man/html3/isalnum.html             comp-c-htmlman          html
@@ -16212,6 +16219,7 @@
 ./usr/share/man/html3/setscrreg.html           comp-c-htmlman          html
 ./usr/share/man/html3/setservent.html          comp-c-htmlman          html
 ./usr/share/man/html3/setstate.html            comp-c-htmlman          html
+./usr/share/man/html3/setsyx.html              comp-c-htmlman          html
 ./usr/share/man/html3/setterm.html             comp-c-htmlman          html
 ./usr/share/man/html3/setttyent.html           comp-c-htmlman          html
 ./usr/share/man/html3/setttyentpath.html       comp-c-htmlman          html
@@ -21258,6 +21266,7 @@
 ./usr/share/man/man3/getskeyprompt.3           comp-c-man              skey,.man
 ./usr/share/man/man3/getstr.3                  comp-c-man              .man
 ./usr/share/man/man3/getsubopt.3               comp-c-man              .man
+./usr/share/man/man3/getsyx.3                  comp-c-man              .man
 ./usr/share/man/man3/gettext.3                 comp-c-man              .man
 ./usr/share/man/man3/gettmode.3                        comp-c-man              .man
 ./usr/share/man/man3/getttyent.3               comp-c-man              .man
@@ -21468,6 +21477,8 @@
 ./usr/share/man/man3/ipsec_strerror.3          comp-c-man              .man
 ./usr/share/man/man3/iruserok.3                        comp-c-man              .man
 ./usr/share/man/man3/iruserok_sa.3             comp-c-man              .man
+./usr/share/man/man3/is_keypad.3               comp-c-man              .man
+./usr/share/man/man3/is_leaveok.3              comp-c-man              .man
 ./usr/share/man/man3/is_linetouched.3          comp-c-man              .man
 ./usr/share/man/man3/is_wintouched.3           comp-c-man              .man
 ./usr/share/man/man3/isalnum.3                 comp-c-man              .man
@@ -23511,6 +23522,7 @@
 ./usr/share/man/man3/setscrreg.3               comp-c-man              .man
 ./usr/share/man/man3/setservent.3              comp-c-man              .man
 ./usr/share/man/man3/setstate.3                        comp-c-man              .man
+./usr/share/man/man3/setsyx.3                  comp-c-man              .man
 ./usr/share/man/man3/setterm.3                 comp-c-man              .man
 ./usr/share/man/man3/setttyent.3               comp-c-man              .man
 ./usr/share/man/man3/setttyentpath.3           comp-c-man              .man
diff -r 5cdd49e9ec01 -r 80af80089b35 lib/libcurses/Makefile
--- a/lib/libcurses/Makefile    Sat Dec 31 11:51:20 2016 +0000
+++ b/lib/libcurses/Makefile    Sat Dec 31 13:50:16 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.72 2016/12/30 22:38:38 roy Exp $
+#      $NetBSD: Makefile,v 1.73 2016/12/31 13:50:16 roy Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/2/94
 
 .include <bsd.own.mk>
@@ -88,7 +88,8 @@
         curses_cursor.3 getpary.3 curses_cursor.3 getparx.3 \
         curses_cursor.3 getparyx.3 curses_fileio.3 getwin.3 \
         curses_input.3 getstr.3 \
-        curses_tty.3 gettmode.3 curses_cursor.3 getyx.3 \
+        curses_tty.3 gettmode.3 \
+        curses_cursor.3 getyx.3 curses_cursor.3 getsyx.3 \
         curses_color.3 has_colors.3 curses_tty.3 has_ic.3 \
         curses_tty.3 halfdelay.3 curses_tty.3 has_il.3 \
         curses_line.3 hline.3 curses_tty.3 idcok.3 \
@@ -98,7 +99,9 @@
         curses_color.3 init_pair.3 curses_screen.3 initscr.3 \
         curses_insertch.3 insch.3 curses_insdelln.3 insdelln.3 \
         curses_insertln.3 insertln.3 curses_inch.3 instr.3 \
-        curses_tty.3 intrflush.3 curses_touch.3 is_linetouched.3 \
+        curses_tty.3 intrflush.3 \
+        curses_pad.3 is_keypad.3 \
+        curses_refresh.3 is_leaveok.3 curses_touch.3 is_linetouched.3 \
         curses_touch.3 is_wintouched.3 curses_screen.3 isendwin.3 \
         curses_keyname.3 keyname.3 \
         curses_input.3 keypad.3 curses_tty.3 killchar.3 \
@@ -140,6 +143,7 @@
         curses_tty.3 savetty.3 curses_scanw.3 scanw.3 \
         curses_scroll.3 scrl.3 curses_scroll.3 scroll.3 \
         curses_scroll.3 scrollok.3 curses_scroll.3 setscrreg.3 \
+        curses_cursor.3 setsyx.3 \
         curses_screen.3 set_term.3 curses_screen.3 setterm.3 \
         curses_standout.3 standend.3 curses_standout.3 standout.3 \
         curses_color.3 start_color.3 curses_pad.3 subpad.3 \
diff -r 5cdd49e9ec01 -r 80af80089b35 lib/libcurses/curses.h
--- a/lib/libcurses/curses.h    Sat Dec 31 11:51:20 2016 +0000
+++ b/lib/libcurses/curses.h    Sat Dec 31 13:50:16 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses.h,v 1.108 2016/12/30 22:38:38 roy Exp $ */
+/*     $NetBSD: curses.h,v 1.109 2016/12/31 13:50:16 roy Exp $ */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -614,6 +614,24 @@
 #define        getmaxyx(w, y, x)       (y) = getmaxy(w), (x) = getmaxx(w)
 #define        getparyx(w, y, x)       (y) = getpary(w), (x) = getparx(w)
 
+#define        getsyx(y, x)                                            \
+       do {                                                    \
+               if (is_leaveok(curscr))                         \
+                       (y) = (x) = -1;                         \
+               else                                            \
+                       getyx(curscr,(y), (x));                 \
+       } while(0 /* CONSTCOND */)
+#define        setsyx(y, x)                                            \
+       do {                                                    \
+               if ((y) == -1 && (x) == -1)                     \
+                       leaveok(curscr, TRUE);                  \
+               else {                                          \
+                       leaveok(curscr, FALSE);                 \
+                       wmove(curscr, (y), (x));                \
+               }                                               \
+       } while(0 /* CONSTCOND */)
+
+
 /* Public function prototypes. */
 __BEGIN_DECLS
 int     assume_default_colors(short, short);
@@ -923,6 +941,10 @@
 void wbkgrndset(WINDOW *, const cchar_t *);
 int wgetbkgrnd(WINDOW *, cchar_t *);
 
+/* ncurses window tests */
+bool is_keypad(const WINDOW *);
+bool is_leaveok(const WINDOW *);
+
 /* Private functions that are needed for user programs prototypes. */
 int     __cputchar(int);
 int     __waddbytes(WINDOW *, const char *, int, attr_t);
diff -r 5cdd49e9ec01 -r 80af80089b35 lib/libcurses/curses_cursor.3
--- a/lib/libcurses/curses_cursor.3     Sat Dec 31 11:51:20 2016 +0000
+++ b/lib/libcurses/curses_cursor.3     Sat Dec 31 13:50:16 2016 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: curses_cursor.3,v 1.7 2010/02/24 13:02:13 drochner Exp $
+.\"    $NetBSD: curses_cursor.3,v 1.8 2016/12/31 13:50:16 roy Exp $
 .\"
 .\" Copyright (c) 2002
 .\"    Brett Lymn (blymn%NetBSD.org@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -30,13 +30,14 @@
 .\" SUCH DAMAGE.
 .\"
 .\"
-.Dd February 23, 2010
+.Dd December 31, 2016
 .Dt CURSES 3
 .Os
 .Sh NAME
 .Nm curses_cursor ,
 .Nm getcury ,
 .Nm getcurx ,
+.Nm getsyx ,
 .Nm getyx ,
 .Nm getbegy ,
 .Nm getbegx ,
@@ -48,6 +49,7 @@
 .Nm getparx ,
 .Nm getparyx ,
 .Nm move ,
+.Nm setsyx ,
 .Nm wmove ,
 .Nm mvcur ,
 .Nm wcursyncup
@@ -60,6 +62,8 @@
 .Fn getcury "WINDOW *win"
 .Ft int
 .Fn getcurx "WINDOW *win"
+.Ft int
+.Fn getsyx "int y" "int x"
 .Ft void
 .Fn getyx "WINDOW *win" "int y" "int x"
 .Ft int
@@ -83,6 +87,8 @@
 .Ft int
 .Fn move "int y" "int x"
 .Ft int
+.Fn setsyx "int y" "int x"
+.Ft int
 .Fn wmove "WINDOW *win" "int y" "int x"
 .Ft int
 .Fn mvcur "int oldy" "int oldx" "int y" "int x"
@@ -107,6 +113,30 @@
 to the current row and column positions of the cursor in the window
 .Fa win .
 .Pp
+The
+.Fn getsyx
+macro sets the values of
+.Fa y
+and
+.Fa x
+of the current window if
+.Fn is_leaveok
+is false, otherwise \-1, \-1.
+The
+.Fn setsyx
+macro sets the row and column positions, respectively, of the cursor in the
+current window to the values of
+.Fa y
+and
+.Fa x.
+If both
+.Fa y
+and
+.Fa x
+are both \-1 then
+.Fn leaveok
+is set.
+.Pp
 The origin row and columns of a window
 .Fa win
 can be
@@ -221,3 +251,11 @@
 .Sh HISTORY
 The Curses package appeared in
 .Bx 4.0 .
+The
+.Fn getsyx
+and
+.Fn setsyx
+functions are
+.Em ncurses
+extensions to the Curses library and were added in
+.Nx 8.0 .
diff -r 5cdd49e9ec01 -r 80af80089b35 lib/libcurses/curses_pad.3
--- a/lib/libcurses/curses_pad.3        Sat Dec 31 11:51:20 2016 +0000
+++ b/lib/libcurses/curses_pad.3        Sat Dec 31 13:50:16 2016 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: curses_pad.3,v 1.4 2008/04/30 13:10:51 martin Exp $
+.\"    $NetBSD: curses_pad.3,v 1.5 2016/12/31 13:50:16 roy Exp $
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
@@ -25,7 +25,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 4, 2002
+.Dd December 31, 2016
 .Dt CURSES_PAD 3
 .Os
 .Sh NAME
@@ -47,6 +47,8 @@
 .Fn prefresh "WINDOW *pad" "int pbeg_y" "int pbeg_x" "int sbeg_y" "int sbeg_x" "int smax_y" "int smax_x"
 .Ft int
 .Fn pnoutrefresh "WINDOW *pad" "int pbeg_y" "int pbeg_x" "int sbeg_y" "int sbeg_x" "int smax_y" "int smax_x"
+.Ft bool
+.Fn is_keypad "const WINDOW *pad"
 .Sh DESCRIPTION
 These functions create and display pads on the current screen.
 .Pp
@@ -108,6 +110,10 @@
 functions can be used together to speed up terminal redraws by
 deferring the actual terminal updates until after a batch of updates
 to multiple pads has been done.
+.Pp
+The
+.Fn is_keypad
+function returns true if the given window is a pad, otherwise false.
 .Sh RETURN VALUES
 Functions returning pointers will return
 .Dv NULL
@@ -140,3 +146,9 @@



Home | Main Index | Thread Index | Old Index