Source-Changes-HG archive

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

[src/trunk]: src Implement is_term_resized and resize_term(3) ncurses extensi...



details:   https://anonhg.NetBSD.org/src/rev/aafcc20c920c
branches:  trunk
changeset: 350138:aafcc20c920c
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Jan 05 21:25:17 2017 +0000

description:
Implement is_term_resized and resize_term(3) ncurses extensions.
resizeterm(3) is now a wrapper for resize_term(3).

diffstat:

 distrib/sets/lists/comp/mi    |   8 ++++++-
 lib/libcurses/Makefile        |   6 +++-
 lib/libcurses/curses.3        |   3 +-
 lib/libcurses/curses.h        |   4 ++-
 lib/libcurses/curses_screen.3 |  27 ++++++++++++++++++++----
 lib/libcurses/resize.c        |  46 ++++++++++++++++++++++++++++++++++++++----
 6 files changed, 79 insertions(+), 15 deletions(-)

diffs (281 lines):

diff -r 4eee62e924df -r aafcc20c920c distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Thu Jan 05 20:37:06 2017 +0000
+++ b/distrib/sets/lists/comp/mi        Thu Jan 05 21:25:17 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2096 2017/01/05 20:31:37 roy Exp $
+#      $NetBSD: mi,v 1.2097 2017/01/05 21:25:18 roy Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -6878,6 +6878,7 @@
 ./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_term_resized.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
 ./usr/share/man/cat3/isalpha.0                 comp-c-catman           .cat
@@ -8676,6 +8677,7 @@
 ./usr/share/man/cat3/reset_prog_mode.0         comp-c-catman           .cat
 ./usr/share/man/cat3/reset_shell_mode.0                comp-c-catman           .cat
 ./usr/share/man/cat3/resetty.0                 comp-c-catman           .cat
+./usr/share/man/cat3/resize_term.0             comp-c-catman           .cat
 ./usr/share/man/cat3/resizeterm.0              comp-c-catman           .cat
 ./usr/share/man/cat3/resolver.0                        comp-c-catman           .cat
 ./usr/share/man/cat3/rewind.0                  comp-c-catman           .cat
@@ -14230,6 +14232,7 @@
 ./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_term_resized.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
 ./usr/share/man/html3/isalpha.html             comp-c-htmlman          html
@@ -15988,6 +15991,7 @@
 ./usr/share/man/html3/reset_prog_mode.html     comp-c-htmlman          html
 ./usr/share/man/html3/reset_shell_mode.html    comp-c-htmlman          html
 ./usr/share/man/html3/resetty.html             comp-c-htmlman          html
+./usr/share/man/html3/resize_term.html         comp-c-htmlman          html
 ./usr/share/man/html3/resizeterm.html          comp-c-htmlman          html
 ./usr/share/man/html3/resolver.html            comp-c-htmlman          html
 ./usr/share/man/html3/rewind.html              comp-c-htmlman          html
@@ -21499,6 +21503,7 @@
 ./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_term_resized.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
 ./usr/share/man/man3/isalpha.3                 comp-c-man              .man
@@ -23297,6 +23302,7 @@
 ./usr/share/man/man3/reset_prog_mode.3         comp-c-man              .man
 ./usr/share/man/man3/reset_shell_mode.3                comp-c-man              .man
 ./usr/share/man/man3/resetty.3                 comp-c-man              .man
+./usr/share/man/man3/resize_term.3             comp-c-man              .man
 ./usr/share/man/man3/resizeterm.3              comp-c-man              .man
 ./usr/share/man/man3/resolver.3                        comp-c-man              .man
 ./usr/share/man/man3/rewind.3                  comp-c-man              .man
diff -r 4eee62e924df -r aafcc20c920c lib/libcurses/Makefile
--- a/lib/libcurses/Makefile    Thu Jan 05 20:37:06 2017 +0000
+++ b/lib/libcurses/Makefile    Thu Jan 05 21:25:17 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.79 2017/01/05 20:31:37 roy Exp $
+#      $NetBSD: Makefile,v 1.80 2017/01/05 21:25:17 roy Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/2/94
 
 .include <bsd.own.mk>
@@ -103,6 +103,7 @@
         curses_tty.3 intrflush.3 \
         curses_pad.3 is_keypad.3 \
         curses_refresh.3 is_leaveok.3 curses_touch.3 is_linetouched.3 \
+        curses_screen.3 is_term_resized.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,7 +141,8 @@
         curses_fileio.3 putwin.3 curses_tty.3 qiflush.3 \
         curses_tty.3 raw.3 curses_refresh.3 refresh.3 \
         curses_tty.3 reset_prog_mode.3 curses_tty.3 reset_shell_mode.3 \
-        curses_tty.3 resetty.3 curses_screen.3 resizeterm.3 \
+        curses_tty.3 resetty.3 \
+        curses_screen.3 resizeterm.3 curses_screen.3 resize_term.3 \
         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 \
diff -r 4eee62e924df -r aafcc20c920c lib/libcurses/curses.3
--- a/lib/libcurses/curses.3    Thu Jan 05 20:37:06 2017 +0000
+++ b/lib/libcurses/curses.3    Thu Jan 05 21:25:17 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: curses.3,v 1.64 2017/01/05 20:31:37 roy Exp $
+.\"    $NetBSD: curses.3,v 1.65 2017/01/05 21:25:18 roy Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -215,6 +215,7 @@
 .It reset_prog_mode Ta Xr curses_tty 3
 .It reset_shell_mode Ta Xr curses_tty 3
 .It resetty Ta Xr curses_tty 3
+.It resize_term Ta Xr curses_screen 3
 .It resizeterm Ta Xr curses_screen 3
 .It savetty Ta Xr curses_tty 3
 .It scanw Ta Xr curses_scanw 3
diff -r 4eee62e924df -r aafcc20c920c lib/libcurses/curses.h
--- a/lib/libcurses/curses.h    Thu Jan 05 20:37:06 2017 +0000
+++ b/lib/libcurses/curses.h    Thu Jan 05 21:25:17 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses.h,v 1.116 2017/01/05 20:31:37 roy Exp $ */
+/*     $NetBSD: curses.h,v 1.117 2017/01/05 21:25:18 roy Exp $ */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -695,6 +695,7 @@
 bool    isendwin(void);
 bool    is_linetouched(WINDOW *, int);
 bool    is_wintouched(WINDOW *);
+bool    is_term_resized(int, int);
 int      keyok(int, bool);
 int     keypad(WINDOW *, bool);
 char   *keyname(int);
@@ -744,6 +745,7 @@
 int     reset_shell_mode(void);
 int     resetty(void);
 int      resizeterm(int, int);
+int     resize_term(int, int);
 int     savetty(void);
 int     scanw(const char *, ...) __scanflike(1, 2);
 int     scroll(WINDOW *);
diff -r 4eee62e924df -r aafcc20c920c lib/libcurses/curses_screen.3
--- a/lib/libcurses/curses_screen.3     Thu Jan 05 20:37:06 2017 +0000
+++ b/lib/libcurses/curses_screen.3     Thu Jan 05 21:25:17 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: curses_screen.3,v 1.20 2017/01/05 20:31:37 roy Exp $
+.\"    $NetBSD: curses_screen.3,v 1.21 2017/01/05 21:25:18 roy Exp $
 .\"
 .\" Copyright (c) 2002
 .\"    Brett Lymn (blymn%NetBSD.org@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -43,6 +43,8 @@
 .Nm endwin ,
 .Nm initscr ,
 .Nm isendwin ,
+.Nm is_term_resized ,
+.Nm resize_term ,
 .Nm resizeterm ,
 .Nm setterm ,
 .Nm set_tabsize
@@ -67,6 +69,10 @@
 .Fn initscr "void"
 .Ft bool
 .Fn isendwin "void"
+.Ft bool
+.Fn is_term_resized "int lines" "int cols"
+.Fn int
+.Fn resize_term "int lines" "int cols"
 .Ft int
 .Fn resizeterm "int lines" "int cols"
 .Ft int
@@ -155,8 +161,8 @@
 screen has occurred since the last call to
 .Fn endwin .
 .Pp
-The size of the screen may be changed  by calling
-.Fn resizeterm
+The size of the screen may be changed by calling
+.Fn resize_term
 with the updated number of lines and columns.
 This will resize the curses internal data structures to accommodate the
 changed terminal geometry.
@@ -167,7 +173,15 @@
 windows and any of their subwindows will be resized to fit the new
 screen size.
 The application must redraw the screen after a call to
-.Fn resizeterm .
+.Fn resize_term .
+The
+.Fn resizeterm
+function is a wrapper for
+.Fn resize_term
+and adjusts other structure data that handles window dimensions.
+The
+.Fn is_term_resized
+function tests if either of the above functions need to be called.
 .Pp
 The
 .Fn setterm
@@ -252,8 +266,11 @@
 extension to the Curses library and was added in
 .Nx 1.6 .
 The
+.Fn is_term_resized ,
+.Fn resize_term
+and
 .Fn set_tabsize
-function is a
+functions are
 .Em ncurses
 extension to the Curses library and was added in
 .Nx 8.0 .
diff -r 4eee62e924df -r aafcc20c920c lib/libcurses/resize.c
--- a/lib/libcurses/resize.c    Thu Jan 05 20:37:06 2017 +0000
+++ b/lib/libcurses/resize.c    Thu Jan 05 21:25:17 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: resize.c,v 1.20 2009/07/22 16:57:15 roy Exp $  */
+/*     $NetBSD: resize.c,v 1.21 2017/01/05 21:25:18 roy Exp $  */
 
 /*
  * Copyright (c) 2001
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)resize.c   blymn 2001/08/26";
 #else
-__RCSID("$NetBSD: resize.c,v 1.20 2009/07/22 16:57:15 roy Exp $");
+__RCSID("$NetBSD: resize.c,v 1.21 2017/01/05 21:25:18 roy Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -136,19 +136,56 @@
 }
 
 /*
+ * is_term_resized --
+ *     Return true if the given dimensions do not match the
+ *     internal structures.
+ */
+bool
+is_term_resized(int nlines, int ncols)
+{
+
+       return (nlines > 0 && ncols > 0 && (nlines != LINES || ncols != COLS));
+}
+
+/*
  * resizeterm --
  *     Resize the terminal window, resizing the dependent windows.
+ *     Handles internal book-keeping.
+ */
+int
+resizeterm(int nlines, int ncols)
+{
+       int result;
+
+#ifdef DEBUG
+       __CTRACE(__CTRACE_WINDOW, "resizeterm: (%d, %d)\n", nlines, ncols);
+#endif
+
+       if (!is_term_resized(nlines, ncols))
+               return OK;
+
+       result = resizeterm(nlines, ncols);
+       clearok(curscr, TRUE);
+       return result;
+}
+
+/*
+ * resize_term --
+ *     Resize the terminal window, resizing the dependent windows.
  */
 int
-resizeterm(int nlines, int ncols)
+resize_term(int nlines, int ncols)
 {
        WINDOW *win;
        struct __winlist *list;
 
 #ifdef DEBUG
-       __CTRACE(__CTRACE_WINDOW, "resizeterm: (%d, %d)\n", nlines, ncols);
+       __CTRACE(__CTRACE_WINDOW, "resize_term: (%d, %d)\n", nlines, ncols);
 #endif
 
+       if (!is_term_resized(nlines, ncols))
+               return OK;
+
        if (__resizeterm(curscr, nlines, ncols) == ERR)
                return ERR;
        if (__resizeterm(__virtscr, nlines, ncols) == ERR)
@@ -167,7 +204,6 @@
                        __swflags(win);
        }
 
-       wrefresh(curscr);
        return OK;
 }
 



Home | Main Index | Thread Index | Old Index