]> granicus.if.org Git - neomutt/commitdiff
Extend the editor so it supports unprintable characters.
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 3 Jan 2001 10:44:23 +0000 (10:44 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 3 Jan 2001 10:44:23 +0000 (10:44 +0000)
enter.c

diff --git a/enter.c b/enter.c
index 13e2fc3e4439cefd5ab9fdc43e359f75e56cbb53..ccf0bd690805527d78360f257d0fd848d1fc6eed 100644 (file)
--- a/enter.c
+++ b/enter.c
@@ -33,11 +33,16 @@ enum
   M_REDRAW_LINE                /* redraw entire line */
 };
 
-/* FIXME: these functions should deal with unprintable characters */
-
 static int my_wcwidth (wchar_t wc)
 {
-  return wcwidth (wc);
+  int n = wcwidth (wc);
+  if (n > 0)
+    return n;
+  if (!(wc & ~0x7f))
+    return 2;
+  if (!(wc & ~0xffff))
+    return 6;
+  return 10;
 }
 
 static int my_wcswidth (const wchar_t *s, size_t n)
@@ -50,7 +55,14 @@ static int my_wcswidth (const wchar_t *s, size_t n)
 
 static int my_addwch (wchar_t wc)
 {
-  return mutt_addwch (wc);
+  int n = wcwidth (wc);
+  if (n > 0)
+    return mutt_addwch (wc);
+  if (!(wc & ~0x7f))
+    return printw ("^%c", ((int)wc + 0x40) & 0x7f);
+  if (!(wc & ~0xffff))
+    return printw ("\\u%04x", (int)wc);
+  return printw ("\\u%08x", (int)wc);
 }
 
 static size_t width_ceiling (const wchar_t *s, size_t n, int w1)