From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17736 invoked from network); 26 Oct 2007 20:14:28 -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; 26 Oct 2007 20:14:28 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 27805 invoked from network); 26 Oct 2007 20:14:22 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Oct 2007 20:14:21 -0000 Received: (qmail 14686 invoked by alias); 26 Oct 2007 20:14:18 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24023 Received: (qmail 14670 invoked from network); 26 Oct 2007 20:14:18 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 26 Oct 2007 20:14:18 -0000 Received: (qmail 27498 invoked from network); 26 Oct 2007 20:14:18 -0000 Received: from mtaout02-winn.ispmail.ntl.com (81.103.221.48) by a.mx.sunsite.dk with SMTP; 26 Oct 2007 20:14:11 -0000 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20071026201408.WDZP25022.mtaout02-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Fri, 26 Oct 2007 21:14:08 +0100 Received: from pws-pc.ntlworld.com ([81.107.45.67]) by aamtaout02-winn.ispmail.ntl.com with ESMTP id <20071026201408.MJQT17393.aamtaout02-winn.ispmail.ntl.com@pws-pc.ntlworld.com> for ; Fri, 26 Oct 2007 21:14:08 +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 l9QKDEiv018227 for ; Fri, 26 Oct 2007 21:13:14 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: curses input X-Mailer: MH-E 8.0.3; nmh 1.2-20070115cvs; GNU Emacs 22.1.1 Date: Fri, 26 Oct 2007 21:13:14 +0100 Message-ID: <18226.1193429594@pws-pc.ntlworld.com> "zcurses input" reads a single character with cbreak and noecho set. Handling nocbreak would be clumsy and the manual says you should use noecho with cbreak. There are all sorts of possible extensions but this is already good enough to do most of what you want. What would be quite nice is to handle keypad mode (see curs_getch(3X)), which would probably mean parsing KEY_* values and converting them to strings to return. We could just return the corresponding integer values, but it seems a cop out. In principle it would be good to have proper zsh input in curses mode, but that's pie in the sky at the moment. Index: configure.ac =================================================================== RCS file: /cvsroot/zsh/zsh/configure.ac,v retrieving revision 1.73 diff -u -r1.73 configure.ac --- configure.ac 24 Oct 2007 08:47:43 -0000 1.73 +++ configure.ac 26 Oct 2007 20:11:00 -0000 @@ -1134,7 +1134,7 @@ brk sbrk \ pathconf sysconf \ tgetent tigetflag tigetnum tigetstr setupterm initscr \ - setcchar waddwstr \ + setcchar waddwstr wget_wch \ pcre_compile pcre_study pcre_exec \ nl_langinfo \ erand48 open_memstream \ Index: Doc/Zsh/mod_curses.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_curses.yo,v retrieving revision 1.10 diff -u -r1.10 mod_curses.yo --- Doc/Zsh/mod_curses.yo 24 Oct 2007 22:23:10 -0000 1.10 +++ Doc/Zsh/mod_curses.yo 26 Oct 2007 20:11:01 -0000 @@ -19,7 +19,8 @@ xitem(tt(zcurses) tt(string) var(targetwin) var(string) ) 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) ] [...]) -item(tt(zcurses) tt(scroll) [ tt(on) | tt(off) | {+/-}var(lines) ])( +xitem(tt(zcurses) tt(scroll) [ tt(on) | tt(off) | {+/-}var(lines) ]) +item(tt(input) var(targetwin) [ var(param) ])( 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 @@ -62,7 +63,11 @@ 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, +to allow the window to be scrolled. + +tt(input) reads a single character from the window without echoing +it back. If var(param) is supplied the character is assigned to the +parameter var(param), else it is assigned to the parameter var(REPLY). ) enditem() Index: Src/Modules/curses.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/curses.c,v retrieving revision 1.22 diff -u -r1.22 curses.c --- Src/Modules/curses.c 24 Oct 2007 22:23:10 -0000 1.22 +++ Src/Modules/curses.c 26 Oct 2007 20:11:01 -0000 @@ -43,6 +43,7 @@ #ifndef MULTIBYTE_SUPPORT # undef HAVE_SETCCHAR # undef HAVE_WADDWSTR +# undef HAVE_WGET_WCH #endif #ifdef HAVE_SETCCHAR @@ -335,6 +336,16 @@ zcurses_colorpairs->printnode = NULL; } + /* + * We use cbreak mode because we don't want line buffering + * on input since we'd just need to loop over characters. + * We use noecho since the manual says that's the right + * thing to do with cbreak. + * + * Turn these on immediately to catch typeahead. + */ + cbreak(); + noecho(); gettyinfo(&curses_tty_state); } else { settyinfo(&curses_tty_state); @@ -669,6 +680,59 @@ } +static int +zccmd_input(const char *nam, char **args) +{ + LinkNode node; + ZCWin w; + char *var; +#ifdef HAVE_WGET_WCH + wint_t wi; + VARARR(char, instr, 2*MB_CUR_MAX+1); +#else + int ci; + instr[3]; +#endif + + 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); + +#ifdef HAVE_WGET_WCH + if (wget_wch(w->win, &wi) == ERR) + return 1; + wctomb(instr, (wchar_t)wi); + if (!*instr) { + instr[0] = Meta; + instr[1] = '\0' ^ 32; + instr[2] = '\0'; + } else { + (void)metafy(instr, strlen(instr), META_NOALLOC); + } +#else + ci = wgetch(w->win); + if (imeta(ci)) { + instr[0] = Meta; + instr[1] = (char)ci ^ 32; + instr[2] = '\0'; + } else { + instr[0] = (char)ci; + instr[1] = '\0'; + } +#endif + if (args[1]) + var = args[1]; + else + var = "REPLY"; + if (!setsparam(var, ztrdup(instr))) + return 1; + return 0; +} + /********************* Main builtin handler *********************/ @@ -693,6 +757,7 @@ {"end", zccmd_endwin, 0, 0}, {"attr", zccmd_attr, 2, -1}, {"scroll", zccmd_scroll, 2, 2}, + {"input", zccmd_input, 1, 2}, {NULL, (zccmd_t)0, 0, 0} }; -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/