zsh-workers
 help / color / mirror / code / Atom feed
* getquery() acts funny with multibyte characters
@ 2008-06-26  9:45 Mikael Magnusson
  2008-06-26 17:01 ` Mikael Magnusson
  2008-06-30 21:46 ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Mikael Magnusson @ 2008-06-26  9:45 UTC (permalink / raw)
  To: zsh-workers

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 å (U+E5) erases one character and entering は (U+306F) erases
two. It seems to happen with unsetopt multibyte too.

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?

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: getquery() acts funny with multibyte characters
  2008-06-26  9:45 getquery() acts funny with multibyte characters Mikael Magnusson
@ 2008-06-26 17:01 ` Mikael Magnusson
  2008-06-30 21:46 ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2008-06-26 17:01 UTC (permalink / raw)
  To: zsh-workers

2008/6/26 Mikael Magnusson <mikachu@gmail.com>:
> 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 å (U+E5) erases one character and entering は (U+306F) erases
> two. It seems to happen with unsetopt multibyte too.
>
> 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?

The current approach is also racey if you type very quickly (and by
type i mean have 1000 * 'b' in the x clipboard and press the middle
mouse button).

% mpalyer
zsh: correct 'mpalyer' to 'mplayer' [nyae]?
bbbbbbbbbbbbbbbbbbbbbbbzsh: command not found: mpalyer

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: getquery() acts funny with multibyte characters
  2008-06-26  9:45 getquery() acts funny with multibyte characters Mikael Magnusson
  2008-06-26 17:01 ` Mikael Magnusson
@ 2008-06-30 21:46 ` Peter Stephenson
  2008-07-01 17:18   ` Mikael Magnusson
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2008-06-30 21:46 UTC (permalink / raw)
  To: zsh-workers

On Thu, 26 Jun 2008 11:45:02 +0200
"Mikael Magnusson" <mikachu@gmail.com> 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 å (U+E5) erases one character and entering は (U+306F) erases
> two. It seems to happen with unsetopt multibyte too.
> 
> 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
===================================================================
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) == 'y');
 }
 
-/**/
-int
-read1char(void)
+static int
+read1char(int echo)
 {
     char c;
 
@@ -2079,6 +2078,8 @@
 	if (errno != EINTR || errflag || retflag || breaks || contflag)
 	    return -1;
     }
+    if (echo)
+	write(SHTTY, &c, 1);
     return STOUC(c);
 }
 
@@ -2105,12 +2106,26 @@
 int
 getquery(char *valid_chars, int purge)
 {
-    int c, d;
+    int c, d, nl = 0;
     int isem = !strcmp(term, "emacs");
+    struct ttyinfo ti;
 
     attachtty(mypgrp);
+
+    gettyinfo(&ti);
+#ifdef HAS_TIO
+    ti.tio.c_lflag &= ~ECHO;
+    if (!isem) {
+	ti.tio.c_lflag &= ~ICANON;
+	ti.tio.c_cc[VMIN] = 1;
+	ti.tio.c_cc[VTIME] = 0;
+    }
+#else
+    ti.sgttyb.sg_flags &= ~ECHO;
     if (!isem)
-	setcbreak();
+	ti.sgttyb.sg_flags |= CBREAK;
+#endif
+    settyinfo(&ti);
 
     if (noquery(purge)) {
 	if (!isem)
@@ -2119,7 +2134,7 @@
 	return 'n';
     }
 
-    while ((c = read1char()) >= 0) {
+    while ((c = read1char(0)) >= 0) {
 	if (c == 'Y')
 	    c = 'y';
 	else if (c == 'N')
@@ -2131,17 +2146,18 @@
 	    break;
 	}
 	if (strchr(valid_chars, c)) {
-	    write(SHTTY, "\n", 1);
+	    nl = 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 != '\n')
-	    while ((d = read1char()) >= 0 && d != '\n');
+	    while ((d = read1char(1)) >= 0 && d != '\n');
     } else {
 	if (c != '\n' && !valid_chars) {
 #ifdef MULTIBYTE_SUPPORT
@@ -2159,19 +2175,17 @@
 
 		    if (ret != MB_INCOMPLETE)
 			break;
-		    c = read1char();
+		    c = read1char(1);
 		    if (c < 0)
 			break;
 		    cc = (char)c;
 		}
 	    }
 #endif
-	    settyinfo(&shttyinfo);
 	    write(SHTTY, "\n", 1);
 	}
-	else
-	    settyinfo(&shttyinfo);
     }
+    settyinfo(&shttyinfo);
     return c;
 }
 

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: getquery() acts funny with multibyte characters
  2008-06-30 21:46 ` Peter Stephenson
@ 2008-07-01 17:18   ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2008-07-01 17:18 UTC (permalink / raw)
  To: zsh-workers

2008/6/30 Peter Stephenson <p.w.stephenson@ntlworld.com>:
> On Thu, 26 Jun 2008 11:45:02 +0200
> "Mikael Magnusson" <mikachu@gmail.com> 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 å (U+E5) erases one character and entering は (U+306F) erases
>> two. It seems to happen with unsetopt multibyte too.
>>
>> 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.

I'm unsure if you were referring to the mail itself or the patch, but in any
case they both (for #2: appear to) work fine. :)

-- 
Mikael Magnusson

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-01 17:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-26  9:45 getquery() acts funny with multibyte characters Mikael Magnusson
2008-06-26 17:01 ` Mikael Magnusson
2008-06-30 21:46 ` Peter Stephenson
2008-07-01 17:18   ` Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).