From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23742 invoked from network); 1 Jul 2008 00:31:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 1 Jul 2008 00:31:06 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 68030 invoked from network); 30 Jun 2008 23:28:03 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 30 Jun 2008 23:28:03 -0000 Received: (qmail 10278 invoked by alias); 30 Jun 2008 22:05:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25259 Received: (qmail 10836 invoked from network); 30 Jun 2008 21:47:30 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 30 Jun 2008 21:47:30 -0000 Received: from mtaout02-winn.ispmail.ntl.com (mtaout02-winn.ispmail.ntl.com [81.103.221.48]) by bifrost.dotsrc.org (Postfix) with ESMTP id 1E6BD80561D0 for ; Mon, 30 Jun 2008 23:47:20 +0200 (CEST) Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20080630215207.DYII7070.mtaout02-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Mon, 30 Jun 2008 22:52:07 +0100 Received: from pws-pc ([81.107.40.67]) by aamtaout03-winn.ispmail.ntl.com with ESMTP id <20080630215720.WXDT8797.aamtaout03-winn.ispmail.ntl.com@pws-pc> for ; Mon, 30 Jun 2008 22:57:20 +0100 Date: Mon, 30 Jun 2008 22:46:54 +0100 From: Peter Stephenson To: zsh-workers Subject: Re: getquery() acts funny with multibyte characters Message-ID: <20080630224654.16b9754e@pws-pc> In-Reply-To: <237967ef0806260245y7e9d8badif35b2fe7892a45b1@mail.gmail.com> References: <237967ef0806260245y7e9d8badif35b2fe7892a45b1@mail.gmail.com> X-Mailer: Claws Mail 3.4.0 (GTK+ 2.12.10; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: ClamAV 0.92.1/7593/Mon Jun 30 23:00:22 2008 on bifrost X-Virus-Status: Clean On Thu, 26 Jun 2008 11:45:02 +0200 "Mikael Magnusson" wrote: > If you misspell a command or run rm * (there are probably other cases > too) you get a prompt that asks you for y/n or whatever is applicable. > If you write a multibyte character at this prompt, zsh will erase a > character of the prompt for every extra byte in the character, ie > entering =C3=A5 (U+E5) erases one character and entering =E3=81=AF (U+306= F) erases > two. It seems to happen with unsetopt multibyte too. >=20 > The function seems to emit "\b \b" to erase what you wrote if it isn't > a valid response, which seems a bit strange. Wouldn't it be more sane > to turn off echoing and simply print the valid response instead? This might work, if the mailing list ever shows up. Index: Src/utils.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.194 diff -u -r1.194 utils.c --- Src/utils.c 10 Jun 2008 08:50:52 -0000 1.194 +++ Src/utils.c 30 Jun 2008 21:43:42 -0000 @@ -2069,9 +2069,8 @@ return (getquery("ny", 1) =3D=3D 'y'); } =20 -/**/ -int -read1char(void) +static int +read1char(int echo) { char c; =20 @@ -2079,6 +2078,8 @@ if (errno !=3D EINTR || errflag || retflag || breaks || contflag) return -1; } + if (echo) + write(SHTTY, &c, 1); return STOUC(c); } =20 @@ -2105,12 +2106,26 @@ int getquery(char *valid_chars, int purge) { - int c, d; + int c, d, nl =3D 0; int isem =3D !strcmp(term, "emacs"); + struct ttyinfo ti; =20 attachtty(mypgrp); + + gettyinfo(&ti); +#ifdef HAS_TIO + ti.tio.c_lflag &=3D ~ECHO; + if (!isem) { + ti.tio.c_lflag &=3D ~ICANON; + ti.tio.c_cc[VMIN] =3D 1; + ti.tio.c_cc[VTIME] =3D 0; + } +#else + ti.sgttyb.sg_flags &=3D ~ECHO; if (!isem) - setcbreak(); + ti.sgttyb.sg_flags |=3D CBREAK; +#endif + settyinfo(&ti); =20 if (noquery(purge)) { if (!isem) @@ -2119,7 +2134,7 @@ return 'n'; } =20 - while ((c =3D read1char()) >=3D 0) { + while ((c =3D read1char(0)) >=3D 0) { if (c =3D=3D 'Y') c =3D 'y'; else if (c =3D=3D 'N') @@ -2131,17 +2146,18 @@ break; } if (strchr(valid_chars, c)) { - write(SHTTY, "\n", 1); + nl =3D 1; break; } zbeep(); - if (icntrl(c)) - write(SHTTY, "\b \b", 3); - write(SHTTY, "\b \b", 3); } + write(SHTTY, &c, 1); + if (nl) + write(SHTTY, "\n", 1); + if (isem) { if (c !=3D '\n') - while ((d =3D read1char()) >=3D 0 && d !=3D '\n'); + while ((d =3D read1char(1)) >=3D 0 && d !=3D '\n'); } else { if (c !=3D '\n' && !valid_chars) { #ifdef MULTIBYTE_SUPPORT @@ -2159,19 +2175,17 @@ =20 if (ret !=3D MB_INCOMPLETE) break; - c =3D read1char(); + c =3D read1char(1); if (c < 0) break; cc =3D (char)c; } } #endif - settyinfo(&shttyinfo); write(SHTTY, "\n", 1); } - else - settyinfo(&shttyinfo); } + settyinfo(&shttyinfo); return c; } =20 --=20 Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/