diff options
| author | roy <roy@NetBSD.org> | 2017-01-10 10:13:24 +0000 |
|---|---|---|
| committer | roy <roy@NetBSD.org> | 2017-01-10 10:13:24 +0000 |
| commit | 43af8cb074e653dbb5a9a478e900b7da36d0152f (patch) | |
| tree | 9c301c901878307cd12a5fa6bee874cd668a99ef /lib/libcurses | |
| parent | 99673ea728e8442acbff9c87a84b689bf186c0f6 (diff) | |
Implement POSIX curses function ripoffline(3).
Diffstat (limited to 'lib/libcurses')
| -rw-r--r-- | lib/libcurses/Makefile | 3 | ||||
| -rw-r--r-- | lib/libcurses/curses.h | 3 | ||||
| -rw-r--r-- | lib/libcurses/curses_private.h | 4 | ||||
| -rw-r--r-- | lib/libcurses/curses_screen.3 | 37 | ||||
| -rw-r--r-- | lib/libcurses/initscr.c | 7 | ||||
| -rw-r--r-- | lib/libcurses/resize.c | 10 | ||||
| -rw-r--r-- | lib/libcurses/screen.c | 78 | ||||
| -rw-r--r-- | lib/libcurses/setterm.c | 8 |
8 files changed, 124 insertions, 26 deletions
diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index a20e45039b1..68ff5cd38d3 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.81 2017/01/05 23:15:43 roy Exp $ +# $NetBSD: Makefile,v 1.82 2017/01/10 10:13:24 roy Exp $ # @(#)Makefile 8.2 (Berkeley) 1/2/94 .include <bsd.own.mk> @@ -143,6 +143,7 @@ MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.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_screen.3 resize_term.3 \ + curses_screen.3 ripoffline.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 --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index 05adafd19f8..a9819525034 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,4 +1,4 @@ -/* $NetBSD: curses.h,v 1.119 2017/01/06 09:14:07 roy Exp $ */ +/* $NetBSD: curses.h,v 1.120 2017/01/10 10:13:24 roy Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -746,6 +746,7 @@ int reset_shell_mode(void); int resetty(void); int resizeterm(int, int); int resize_term(int, int); +int ripoffline(int, int (*)(WINDOW *, int)); int savetty(void); int scanw(const char *, ...) __scanflike(1, 2); int scroll(WINDOW *); diff --git a/lib/libcurses/curses_private.h b/lib/libcurses/curses_private.h index bf42b64e4e2..81556a3f603 100644 --- a/lib/libcurses/curses_private.h +++ b/lib/libcurses/curses_private.h @@ -1,4 +1,4 @@ -/* $NetBSD: curses_private.h,v 1.57 2017/01/06 09:14:07 roy Exp $ */ +/* $NetBSD: curses_private.h,v 1.58 2017/01/10 10:13:24 roy Exp $ */ /*- * Copyright (c) 1998-2000 Brett Lymn @@ -201,6 +201,8 @@ struct __screen { int lx, ly; /* loop parameters for refresh */ int COLS; /* Columns on the screen. */ int LINES; /* Lines on the screen. */ + int ripped_top; /* Lines ripped from the top of the screen. */ + int ripped_bottom; /* Lines ripped from the bottom. */ int ESCDELAY; /* Delay between keys in esc seq's. */ #define ESCDELAY_DEFAULT 300 /* milliseconds. */ int TABSIZE; /* Size of a tab. */ diff --git a/lib/libcurses/curses_screen.3 b/lib/libcurses/curses_screen.3 index 8b560dbca2d..9f165e8dc65 100644 --- a/lib/libcurses/curses_screen.3 +++ b/lib/libcurses/curses_screen.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: curses_screen.3,v 1.21 2017/01/05 21:25:18 roy Exp $ +.\" $NetBSD: curses_screen.3,v 1.22 2017/01/10 10:13:24 roy Exp $ .\" .\" Copyright (c) 2002 .\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au) @@ -30,12 +30,13 @@ .\" SUCH DAMAGE. .\" .\" -.Dd January 5, 2017 +.Dd January 9, 2017 .Dt CURSES_SCREEN 3 .Os .Sh NAME .Nm curses_screen , .Nm filter , +.Nm ripoffline , .Nm use_env , .Nm newterm , .Nm set_term , @@ -55,6 +56,8 @@ .In curses.h .Ft void .Fn filter "void" +.Ft int +.Fn ripoffline "int line" "int (*init)(WINDOW *win, int cols)" .Ft void .Fn use_env "bool value" .Ft SCREEN * @@ -212,6 +215,36 @@ Set lines equal to 1. .El .Pp The +.Fn ripoffline +funcion will rip a line from +.Dv stdscr +at the top if +.Fa line +is positive, or at the bottom if negative. +When +.Fn initscr +or +.Fn newterm +is called, a window will be created for each line ripped and passed +to the +.Fa init +function pointer alongwith the number of columns in the window. +This init function cannot use the +.Dv LINES +or +.Dv COLS +variables and cannot call +.Xr wrefresh 3 +or +.Xr doupdate 3 , +but may call +.Xr wnoutrefresh 3 . +.Dv LINES +will be reduced by the total number of lines ripped off. +.Fn ripoffline +can be called up to five times. +.Pp +The .Fn use_env function determines whether the environment variables .Ev LINES diff --git a/lib/libcurses/initscr.c b/lib/libcurses/initscr.c index ade51d493c6..d6a8c0d04b4 100644 --- a/lib/libcurses/initscr.c +++ b/lib/libcurses/initscr.c @@ -1,4 +1,4 @@ -/* $NetBSD: initscr.c,v 1.30 2017/01/06 13:53:18 roy Exp $ */ +/* $NetBSD: initscr.c,v 1.31 2017/01/10 10:13:24 roy Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)initscr.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: initscr.c,v 1.30 2017/01/06 13:53:18 roy Exp $"); +__RCSID("$NetBSD: initscr.c,v 1.31 2017/01/10 10:13:24 roy Exp $"); #endif #endif /* not lint */ @@ -73,7 +73,8 @@ initscr(void) __rawmode = _cursesi_screen->rawmode; __noqch = _cursesi_screen->noqch; COLS = _cursesi_screen->COLS; - LINES = _cursesi_screen->LINES; + LINES = _cursesi_screen->LINES + - _cursesi_screen->ripped_top - _cursesi_screen->ripped_bottom; COLORS = _cursesi_screen->COLORS; COLOR_PAIRS = _cursesi_screen->COLOR_PAIRS; __GT = _cursesi_screen->GT; diff --git a/lib/libcurses/resize.c b/lib/libcurses/resize.c index 3a49a7c55c0..d433eda4508 100644 --- a/lib/libcurses/resize.c +++ b/lib/libcurses/resize.c @@ -1,4 +1,4 @@ -/* $NetBSD: resize.c,v 1.22 2017/01/06 13:53:18 roy Exp $ */ +/* $NetBSD: resize.c,v 1.23 2017/01/10 10:13:24 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.22 2017/01/06 13:53:18 roy Exp $"); +__RCSID("$NetBSD: resize.c,v 1.23 2017/01/10 10:13:24 roy Exp $"); #endif #endif /* not lint */ @@ -144,7 +144,10 @@ bool is_term_resized(int nlines, int ncols) { - return (nlines > 0 && ncols > 0 && (nlines != LINES || ncols != COLS)); + return (nlines > 0 && ncols > 0 && + (nlines != _cursesi_screen->LINES + + _cursesi_screen->ripped_top + _cursesi_screen->ripped_bottom || + ncols != _cursesi_screen->COLS)); } /* @@ -190,6 +193,7 @@ resize_term(int nlines, int ncols) return ERR; if (__resizeterm(__virtscr, nlines, ncols) == ERR) return ERR; + nlines -= _cursesi_screen->ripped_top - _cursesi_screen->ripped_bottom; if (__resizeterm(stdscr, nlines, ncols) == ERR) return ERR; diff --git a/lib/libcurses/screen.c b/lib/libcurses/screen.c index dd743f78488..8d9d0e02fed 100644 --- a/lib/libcurses/screen.c +++ b/lib/libcurses/screen.c @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.27 2017/01/06 13:53:18 roy Exp $ */ +/* $NetBSD: screen.c,v 1.28 2017/01/10 10:13:24 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.27 2017/01/06 13:53:18 roy Exp $"); +__RCSID("$NetBSD: screen.c,v 1.28 2017/01/10 10:13:24 roy Exp $"); #endif #endif /* not lint */ @@ -45,6 +45,14 @@ __RCSID("$NetBSD: screen.c,v 1.27 2017/01/06 13:53:18 roy Exp $"); static int filtered; +/* List of ripoffline calls */ +#define NRIPS 5 +static struct ripoff { + int nlines; + int (*init)(WINDOW *, int); +} ripoffs[NRIPS]; +static int nrips; + /* * filter has to be called before either initscr or newterm. */ @@ -56,6 +64,24 @@ filter(void) } /* + *ripoffline -- + * Ripoff a line from the top of bottom of stdscr. + * Must be called before initscr or newterm. + */ +int +ripoffline(int line, int (*init)(WINDOW *, int)) +{ + + if (nrips >= NRIPS || init == NULL) + return ERR; /* This makes sense, but not standards compliant. */ + if (line == 0) + return OK; + ripoffs[nrips].nlines = line < 0 ? -1 : 1; + ripoffs[nrips++].init = init; + return OK; +} + +/* * set_term -- * Change the term to the given screen. * @@ -72,7 +98,8 @@ set_term(SCREEN *new) old_screen->rawmode = __rawmode; old_screen->noqch = __noqch; old_screen->COLS = COLS; - old_screen->LINES = LINES; + old_screen->LINES = LINES + + old_screen->ripped_top + old_screen->ripped_bottom; old_screen->COLORS = COLORS; old_screen->COLOR_PAIRS = COLOR_PAIRS; old_screen->GT = __GT; @@ -87,7 +114,7 @@ set_term(SCREEN *new) __rawmode = new->rawmode; __noqch = new->noqch; COLS = new->COLS; - LINES = new->LINES; + LINES = new->LINES - new->ripped_top - new->ripped_bottom; COLORS = new->COLORS; COLOR_PAIRS = new->COLOR_PAIRS; __GT = new->GT; @@ -124,6 +151,7 @@ newterm(char *type, FILE *outfd, FILE *infd) { SCREEN *new_screen; char *sp; + int i; sp = type; if (type == NULL && (sp = getenv("TERM")) == NULL) @@ -158,7 +186,8 @@ newterm(char *type, FILE *outfd, FILE *infd) new_screen->unget_len = 32; if ((new_screen->unget_list = - malloc(sizeof(wchar_t) * new_screen->unget_len)) == NULL) { + malloc(sizeof(wchar_t) * new_screen->unget_len)) == NULL) + { goto error_exit; } new_screen->unget_pos = 0; @@ -180,21 +209,48 @@ newterm(char *type, FILE *outfd, FILE *infd) 0, 0, 0, FALSE)) == NULL) goto error_exit; - if ((new_screen->stdscr = __newwin(new_screen, 0, - 0, 0, 0, FALSE)) == NULL) { + if ((new_screen->__virtscr = __newwin(new_screen, 0, + 0, 0, 0, FALSE)) == NULL) + { delwin(new_screen->curscr); goto error_exit; } - clearok(new_screen->stdscr, 1); + for (i = 0; i < nrips; i++) { + const struct ripoff *r = &ripoffs[i]; + int nlines = r->nlines < 0 ? -r->nlines : r->nlines; + WINDOW *w; + + w = __newwin(new_screen, nlines, 0, + r->nlines < 0 ? LINES + r->nlines : new_screen->ripped_top, + 0, FALSE); + if (w != NULL) { + if (r->nlines < 0) + new_screen->ripped_bottom += nlines; + else + new_screen->ripped_top += nlines; + LINES -= nlines; + } + r->init(w, COLS); +#ifdef DEBUG + if (w != NULL) + __CTRACE(__CTRACE_SCREEN, + "newterm: ripped %d lines from the %s\n", + nlines, r->nlines < 0 ? "bottom" : "top"); +#endif + } + nrips = 0; /* Reset the stack. */ - if ((new_screen->__virtscr = __newwin(new_screen, 0, - 0, 0, 0, FALSE)) == NULL) { + new_screen->stdscr = __newwin(new_screen, LINES, 0, + new_screen->ripped_top, 0, FALSE); + if (new_screen->stdscr == NULL) { delwin(new_screen->curscr); - delwin(new_screen->stdscr); + delwin(new_screen->__virtscr); goto error_exit; } + clearok(new_screen->stdscr, 1); + __init_getch(new_screen); __init_acs(new_screen); #ifdef HAVE_WCHAR diff --git a/lib/libcurses/setterm.c b/lib/libcurses/setterm.c index 52edbbe555f..3eab327e159 100644 --- a/lib/libcurses/setterm.c +++ b/lib/libcurses/setterm.c @@ -1,4 +1,4 @@ -/* $NetBSD: setterm.c,v 1.59 2017/01/06 13:53:18 roy Exp $ */ +/* $NetBSD: setterm.c,v 1.60 2017/01/10 10:13:24 roy Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)setterm.c 8.8 (Berkeley) 10/25/94"; #else -__RCSID("$NetBSD: setterm.c,v 1.59 2017/01/06 13:53:18 roy Exp $"); +__RCSID("$NetBSD: setterm.c,v 1.60 2017/01/10 10:13:24 roy Exp $"); #endif #endif /* not lint */ @@ -150,7 +150,7 @@ _cursesi_setterm(char *type, SCREEN *screen) if (screen->COLS <= 4) return ERR; - LINES = screen->LINES; + LINES = screen->LINES - screen->ripped_top - screen->ripped_bottom; COLS = screen->COLS; ESCDELAY = screen->ESCDELAY; TABSIZE = screen->TABSIZE; @@ -282,7 +282,7 @@ void _cursesi_resetterm(SCREEN *screen) { - LINES = screen->LINES; + LINES = screen->LINES - screen->ripped_top - screen->ripped_bottom; COLS = screen->COLS; ESCDELAY = screen->ESCDELAY; TABSIZE = screen->TABSIZE; |
