From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22220 invoked from network); 24 Oct 2007 22:20:42 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 24 Oct 2007 22:20:42 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 10216 invoked from network); 24 Oct 2007 22:20:36 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Oct 2007 22:20:36 -0000 Received: (qmail 11977 invoked by alias); 24 Oct 2007 22:20:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24018 Received: (qmail 11960 invoked from network); 24 Oct 2007 22:20:33 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 24 Oct 2007 22:20:33 -0000 Received: (qmail 9918 invoked from network); 24 Oct 2007 22:20:33 -0000 Received: from mtaout02-winn.ispmail.ntl.com (81.103.221.48) by a.mx.sunsite.dk with SMTP; 24 Oct 2007 22:20:26 -0000 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20071024222024.JHVB25022.mtaout02-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Wed, 24 Oct 2007 23:20:24 +0100 Received: from pws-pc.ntlworld.com ([81.107.45.67]) by aamtaout02-winn.ispmail.ntl.com with ESMTP id <20071024222024.LLMW17393.aamtaout02-winn.ispmail.ntl.com@pws-pc.ntlworld.com> for ; Wed, 24 Oct 2007 23:20:24 +0100 Received: from pws-pc.ntlworld.com (pws-pc.ntlworld.com [127.0.0.1]) by pws-pc.ntlworld.com (8.14.1/8.13.8) with ESMTP id l9OMJVKW021131 for ; Wed, 24 Oct 2007 23:19:31 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: scrolling X-Mailer: MH-E 8.0.3; nmh 1.2-20070115cvs; GNU Emacs 22.1.1 Date: Wed, 24 Oct 2007 23:19:31 +0100 Message-ID: <21130.1193264371@pws-pc.ntlworld.com> This adds scrolling of windows to zcurses. However, I wouldn't like anybody think I'm a complete geek who spends all his time fiddling with software. Index: Doc/Zsh/mod_curses.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_curses.yo,v retrieving revision 1.9 diff -u -r1.9 mod_curses.yo --- Doc/Zsh/mod_curses.yo 24 Oct 2007 21:53:48 -0000 1.9 +++ Doc/Zsh/mod_curses.yo 24 Oct 2007 22:19:29 -0000 @@ -18,7 +18,8 @@ xitem(tt(zcurses) tt(char) var(targetwin) var(character) ) xitem(tt(zcurses) tt(string) var(targetwin) var(string) ) xitem(tt(zcurses) tt(border) var(targetwin) var(border) )( -item(tt(zcurses) tt(attr) var(targetwin) [ var({+/-}attribute) | var(fg_col)tt(/)var(bg_col) ] [...])( +xitem(tt(zcurses) tt(attr) var(targetwin) [ var({+/-}attribute) | var(fg_col)tt(/)var(bg_col) ] [...]) +item(tt(zcurses) tt(scroll) [ tt(on) | tt(off) | {+/-}var(lines) ])( Manipulate curses windows. All uses of this command should be bracketed by `tt(zcurses init)' to initialise use of curses, and `tt(zcurses end)' to end it; omitting `tt(zcurses end)' can cause @@ -53,6 +54,15 @@ and tt(underline). Each var(fg_col)tt(/)var(bg_col) (to be read as `var(fg_col) on var(bg_col)') sets the foreground and background color for character output. + +tt(scroll) can be used with tt(on) or tt(off) to enabled or disable +scrolling of a window when the cursor would otherwise move below the +window due to typing or output. It can also be used with a positive +or negative integer to scroll the window up or down the given number +of lines without changing the current cursor position (which therefore +appears to move in the opposite direction relative to the window). +In the second case, if scrolling is tt(off) it is temporarily turned tt(on) +to allow the window to be scrolled, ) enditem() Index: Src/Modules/curses.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v retrieving revision 1.21 diff -u -r1.21 curses.c --- Src/Modules/curses.c 24 Oct 2007 21:53:49 -0000 1.21 +++ Src/Modules/curses.c 24 Oct 2007 22:19:29 -0000 @@ -51,9 +51,15 @@ #include +enum zc_win_flags { + /* Scrolling enabled */ + ZCWF_SCROLL = 0x0001 +}; + typedef struct zc_win { WINDOW *win; char *name; + int flags; } *ZCWin; struct zcurses_namenumberpair { @@ -620,6 +626,49 @@ } +static int +zccmd_scroll(const char *nam, char **args) +{ + LinkNode node; + ZCWin w; + int ret = 0; + + node = zcurses_validate_window(args[0], ZCURSES_USED); + if (node == NULL) { + zwarnnam(nam, "%s: %s", zcurses_strerror(zc_errno), args[0]); + return 1; + } + + w = (ZCWin)getdata(node); + + if (!strcmp(args[1], "on")) { + if (scrollok(w->win, TRUE) == ERR) + return 1; + w->flags |= ZCWF_SCROLL; + } else if (!strcmp(args[1], "off")) { + if (scrollok(w->win, FALSE) == ERR) + return 1; + w->flags &= ~ZCWF_SCROLL; + } else { + char *endptr; + zlong sl = zstrtol(args[1], &endptr, 10); + if (*endptr) { + zwarnnam(nam, "scroll requires `on', `off' or integer: %s", + args[1]); + return 1; + } + if (!(w->flags & ZCWF_SCROLL)) + scrollok(w->win, TRUE); + if (wscrl(w->win, (int)sl) == ERR) + ret = 1; + if (!(w->flags & ZCWF_SCROLL)) + scrollok(w->win, FALSE); + } + + return ret; +} + + /********************* Main builtin handler *********************/ @@ -643,6 +692,7 @@ {"border", zccmd_border, 1, 1}, {"end", zccmd_endwin, 0, 0}, {"attr", zccmd_attr, 2, -1}, + {"scroll", zccmd_scroll, 2, 2}, {NULL, (zccmd_t)0, 0, 0} }; -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/