Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: multibyte characters in prompt substitution
- X-seq: zsh-workers 21869
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: multibyte characters in prompt substitution
- Date: Thu, 13 Oct 2005 13:58:20 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
This should fix the output of mulibyte characters in text resulting
from % substitutions in prompts.
The other bit is a mistake in the code I was copying from.
Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.25
diff -u -r1.25 prompt.c
--- Src/prompt.c 22 Sep 2005 01:36:35 -0000 1.25
+++ Src/prompt.c 13 Oct 2005 12:55:40 -0000
@@ -736,6 +736,46 @@
void
stradd(char *d)
{
+#ifdef ZLE_UNICODE_SUPPORT
+ char *ums, *ups;
+ int upslen;
+ mbstate_t ps;
+
+ memset(&ps, 0, sizeof(ps));
+ ums = ztrdup(d);
+ ups = unmetafy(ums, &upslen);
+
+ /*
+ * We now have a raw string of possibly multibyte characters.
+ * Read each character one by one.
+ */
+ while (upslen > 0) {
+ wchar_t cc;
+ char *pc;
+ int ret = mbrtowc(&cc, ups, upslen, &ps);
+
+ if (ret <= 0)
+ {
+ /* Bad character. Take the next byte on its own. */
+ pc = nicechar(*ups);
+ ret = 1;
+ } else {
+ /* Take full wide character in one go */
+ pc = wcs_nicechar(cc, NULL, NULL);
+ }
+ /* Keep output as metafied string. */
+ addbufspc(strlen(pc));
+
+ upslen -= ret;
+ ups += ret;
+
+ /* Put printed representation into the buffer */
+ while (*pc)
+ *bp++ = *pc++;
+ }
+
+ free(ums);
+#else
char *ps, *pc;
addbufspc(niceztrlen(d));
/* This loop puts the nice representation of the string into the prompt *
@@ -743,6 +783,7 @@
for(ps=d; *ps; ps++)
for(pc=nicechar(*ps == Meta ? STOUC(*++ps)^32 : STOUC(*ps)); *pc; pc++)
*bp++ = *pc;
+#endif
}
/* tsetcap(), among other things, can write a termcap string into the buffer. */
Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.75
diff -u -r1.75 complist.c
--- Src/Zle/complist.c 4 Oct 2005 14:27:13 -0000 1.75
+++ Src/Zle/complist.c 13 Oct 2005 12:55:41 -0000
@@ -599,7 +599,7 @@
* an input NULL, which we want to be a real character
* rather than terminator.
*/
- sptr = nicechar(*s);
+ sptr = nicechar(*uptr);
/* everything here is ASCII... */
width = strlen(sptr);
wptr = sptr + width;
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author