From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers <zsh-workers@sunsite.dk>
Subject: Re: getquery() acts funny with multibyte characters
Date: Mon, 30 Jun 2008 22:46:54 +0100 [thread overview]
Message-ID: <20080630224654.16b9754e@pws-pc> (raw)
In-Reply-To: <237967ef0806260245y7e9d8badif35b2fe7892a45b1@mail.gmail.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.
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/
next prev parent reply other threads:[~2008-07-01 0:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-26 9:45 Mikael Magnusson
2008-06-26 17:01 ` Mikael Magnusson
2008-06-30 21:46 ` Peter Stephenson [this message]
2008-07-01 17:18 ` Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080630224654.16b9754e@pws-pc \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).