* PATCH: multibyte characters in prompt substitution
@ 2005-10-13 12:58 Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2005-10-13 12:58 UTC (permalink / raw)
To: Zsh hackers list
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@csr.com> 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-10-13 12:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-13 12:58 PATCH: multibyte characters in prompt substitution Peter Stephenson
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).