From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24878 invoked from network); 28 Oct 2007 20:27:22 -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; 28 Oct 2007 20:27:22 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 43845 invoked from network); 28 Oct 2007 20:27:15 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 28 Oct 2007 20:27:15 -0000 Received: (qmail 24004 invoked by alias); 28 Oct 2007 20:27:12 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24028 Received: (qmail 23987 invoked from network); 28 Oct 2007 20:27:11 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 28 Oct 2007 20:27:11 -0000 Received: (qmail 43531 invoked from network); 28 Oct 2007 20:27:11 -0000 Received: from mtaout02-winn.ispmail.ntl.com (81.103.221.48) by a.mx.sunsite.dk with SMTP; 28 Oct 2007 20:27:04 -0000 Received: from aamtaout04-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20071028202659.YVSC25022.mtaout02-winn.ispmail.ntl.com@aamtaout04-winn.ispmail.ntl.com> for ; Sun, 28 Oct 2007 20:26:59 +0000 Received: from pws-pc.ntlworld.com ([81.107.45.67]) by aamtaout04-winn.ispmail.ntl.com with SMTP id <20071028202658.RDWY29112.aamtaout04-winn.ispmail.ntl.com@pws-pc.ntlworld.com> for ; Sun, 28 Oct 2007 20:26:58 +0000 Date: Sun, 28 Oct 2007 20:26:53 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: PATCH: subwindows, touching, better refreshing Message-Id: <20071028202653.db65f400.p.w.stephenson@ntlworld.com> In-Reply-To: <7423.1193599839@pws-pc.ntlworld.com> References: <7423.1193599839@pws-pc.ntlworld.com> X-Mailer: Sylpheed 2.3.1 (GTK+ 2.10.14; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 28 Oct 2007 19:30:39 +0000 Peter Stephenson wrote: > Use the function keys to move round a rectangle. You get a warning > and a second's delay if you hit the edge (input timeouts won't be hard > since curses does the hard work and they're on my list). They weren't, except I kept getting the function wrong. curses_bang() { # Arrow keys to move, anything else to exit. zmodload zsh/curses local REPLY key newkey integer h=$(( LINES - 10 )) w=$((COLUMNS - 20)) integer x=1 y=1 bang() { zcurses addwin bang 1 5 $(( y + 5 )) $(( x + 10 )) zcurses attr bang red/green bold zcurses string bang 'BANG!' zcurses refresh bang zcurses timeout bang 1000 zcurses input bang REPLY key zcurses delwin bang zcurses touch main zcurses refresh stdscr main } { zcurses init zcurses addwin main $(( LINES - 10 )) $(( COLUMNS - 20 )) 5 10 zcurses border main zcurses move main $y $x zcurses refresh main while true; do if [[ -z $key ]]; then zcurses input main REPLY key fi newkey=$key key= case $newkey in (UP) if (( y == 1 )); then bang else zcurses string main "^" (( y-- )) zcurses move main $y $x zcurses refresh main fi ;; (DOWN) if (( y == h - 2 )); then bang else zcurses string main "v" (( y++ )) zcurses move main $y $x zcurses refresh main fi ;; (LEFT) if (( x == 1 )); then bang else zcurses string main "<" (( x-- )) zcurses move main $y $x zcurses refresh main fi ;; (RIGHT) if (( x == w - 2 )); then bang else zcurses string main ">" (( x++ )) zcurses move main $y $x zcurses refresh main fi ;; ("") break ;; esac done } always { zcurses delwin main zcurses end } } Index: Doc/Zsh/mod_curses.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_curses.yo,v retrieving revision 1.16 diff -u -r1.16 mod_curses.yo --- Doc/Zsh/mod_curses.yo 28 Oct 2007 19:52:40 -0000 1.16 +++ Doc/Zsh/mod_curses.yo 28 Oct 2007 20:23:35 -0000 @@ -23,7 +23,8 @@ xitem(tt(zcurses) tt(border) var(targetwin) var(border) )( xitem(tt(zcurses) tt(attr) var(targetwin) [ var({+/-}attribute) | var(fg_col)tt(/)var(bg_col) ] [...]) xitem(tt(zcurses) tt(scroll) [ tt(on) | tt(off) | {+/-}var(lines) ]) -item(tt(input) var(targetwin) [ var(param) [ var(kpparm) ] ])( +xitem(tt(zcurses) tt(input) var(targetwin) [ var(param) [ var(kpparm) ] ]) +item(tt(zcurses) tt(timeout) var(targetwin) var(intval))( 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 @@ -125,6 +126,14 @@ var(param) as before. On a succesful return only one of var(param) or var(kpparm) contains a non-empty string; the other is set to an empty string. + +tt(timeout) specifies a timeout value for input from var(targetwin). +If var(intval) is negative, `tt(zcurses input)' waits indefinitely for +a character to be typed; this is the default. If var(intval) is zero, +`tt(zcurses input)' returns immediately; if there is typeahead it is +returned, else no input is done and status 1 is returned. If var(intval) +is positive, `tt(zcurses input)' waits var(intval) milliseconds for +input and if there is none at the end of that period returns status 1. ) enditem() Index: Src/Modules/curses.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v retrieving revision 1.28 diff -u -r1.28 curses.c --- Src/Modules/curses.c 28 Oct 2007 19:52:41 -0000 1.28 +++ Src/Modules/curses.c 28 Oct 2007 20:23:35 -0000 @@ -562,7 +562,7 @@ static int -zccmd_move(const char *nam, char **args) +zccmd_move(const char *nam, char **args) { int y, x; LinkNode node; @@ -936,6 +936,33 @@ static int +zccmd_timeout(const char *nam, char **args) +{ + LinkNode node; + ZCWin w; + int to; + char *eptr; + + 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); + + to = (int)zstrtol(args[1], &eptr, 10); + if (*eptr) { + zwarnnam(nam, "timeout requires an integer: %s", args[1]); + return 1; + } + + wtimeout(w->win, to); + return 0; +} + + +static int zccmd_position(const char *nam, char **args) { LinkNode node; @@ -1019,6 +1046,7 @@ {"attr", zccmd_attr, 2, -1}, {"scroll", zccmd_scroll, 2, 2}, {"input", zccmd_input, 1, 3}, + {"timeout", zccmd_timeout, 2, 2}, {"touch", zccmd_touch, 1, -1}, {NULL, (zccmd_t)0, 0, 0} }; -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/