Created
July 19, 2012 13:31
-
-
Save saitoha/3143922 to your computer and use it in GitHub Desktop.
Unicode(UTF-8) support for GNU Screen's OSC/AKA/hardstatus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/ansi.c b/src/ansi.c | |
index d88e153..fc42a0a 100644 | |
--- a/src/ansi.c | |
+++ b/src/ansi.c | |
@@ -1493,8 +1493,24 @@ int c; | |
{ | |
if (curr->w_stringp >= curr->w_string + MAXSTR - 1) | |
curr->w_state = LIT; | |
+# ifdef UTF8 | |
+ else if (c < 0x80) | |
+ *(curr->w_stringp)++ = c; | |
+ else if (c < 0x800) | |
+ { | |
+ *(curr->w_stringp)++ = (c >> 6) | 0xc0; | |
+ *(curr->w_stringp)++ = (c & 0x3f) | 0xc0; | |
+ } | |
+ else /* if (c < 0x10000) */ | |
+ { | |
+ *(curr->w_stringp)++ = (c >> 12) | 0xe0; | |
+ *(curr->w_stringp)++ = (c >> 6) & 0x3f | 0x80; | |
+ *(curr->w_stringp)++ = (c & 0x3f) | 0x80; | |
+ } | |
+# else | |
else | |
*(curr->w_stringp)++ = c; | |
+# endif | |
} | |
/* | |
@@ -1605,7 +1621,7 @@ StringEnd() | |
} | |
return -1; | |
case DCS: | |
- LAY_DISPLAYS(&curr->w_layer, AddStr(curr->w_string)); | |
+ LAY_DISPLAYS(&curr->w_layer, AddRawStr(curr->w_string)); | |
break; | |
case AKA: | |
if (curr->w_title == curr->w_akabuf && !*curr->w_string) | |
@@ -2239,7 +2255,11 @@ int l; | |
c = (unsigned char)*s++; | |
if (c == 0) | |
break; | |
+#ifdef UTF8 | |
+ if (c < 32) | |
+#else | |
if (c < 32 || c == 127 || (c >= 128 && c < 160 && p->w_c1)) | |
+#endif | |
continue; | |
p->w_akachange[i++] = c; | |
} | |
diff --git a/src/display.c b/src/display.c | |
index 94c05f1..85f4cd8 100644 | |
--- a/src/display.c | |
+++ b/src/display.c | |
@@ -2885,7 +2885,7 @@ char *s; | |
D_xtermosc[i] = 1; | |
AddStr("\033]"); | |
AddStr(oscs[i][0]); | |
- AddStr(s); | |
+ AddRawStr(s); | |
AddChar(7); | |
} | |
@@ -2926,6 +2926,18 @@ char *str; | |
} | |
void | |
+AddRawStr(str) | |
+char *str; | |
+{ | |
+ register char c; | |
+ | |
+ ASSERT(display); | |
+ | |
+ while ((c = *str++)) | |
+ AddChar(c); | |
+} | |
+ | |
+void | |
AddStrn(str, n) | |
char *str; | |
int n; | |
diff --git a/src/layer.c b/src/layer.c | |
index 1ae7972..9982a2f 100644 | |
--- a/src/layer.c | |
+++ b/src/layer.c | |
@@ -439,6 +439,7 @@ int x, y; | |
struct viewport *vp; | |
int xs2, xe2, y2, len, len2; | |
struct mchar or; | |
+ int i; | |
if (x + n > l->l_width) | |
n = l->l_width - x; | |
@@ -473,18 +474,15 @@ int x, y; | |
continue; | |
GotoPos(xs2, y2); | |
SetRendition(r); | |
+ for (i = xs2; i <= xe2; ++i) | |
+ PUTCHARLP(' '); | |
+ | |
+ GotoPos(xs2, y2); | |
+ SetRendition(r); | |
len2 = xe2 - (x + vp->v_xoff) + 1; | |
if (len2 > len) | |
len2 = len; | |
PutWinMsg(s, xs2 - x - vp->v_xoff, len2); | |
- xs2 = x + vp->v_xoff + len2; | |
- if (xs2 < vp->v_xs) | |
- xs2 = vp->v_xs; | |
- or = D_rend; | |
- GotoPos(xs2, y2); | |
- SetRendition(&or); | |
- while (xs2++ <= xe2) | |
- PUTCHARLP(' '); | |
} | |
); | |
} | |
diff --git a/src/screen.c b/src/screen.c | |
index 949df01..1f8909f 100644 | |
--- a/src/screen.c | |
+++ b/src/screen.c | |
@@ -3080,8 +3080,32 @@ int start, max; | |
{ | |
if (start-- > 0) | |
s++; | |
- else | |
+#ifdef UTF8 | |
+ else if ((unsigned char)*s < 0x80) | |
+ { | |
+ PUTCHARLP(*s++); | |
+ } | |
+ else if ((unsigned char)*s < 0xe0) | |
+ { | |
+ int first = (*s++ & 0x1f) << 6; | |
+ int second = *s++ & 0x3f; | |
+ AddUtf8(first | second); | |
+ n -= 1; | |
+ start -= 1; | |
+ } | |
+ else /* if (*s2 < 0xf0) */ | |
+ { | |
+ int first = (*s++ & 0x1f) << 12; | |
+ int second = (*s++ & 0x3f) << 6; | |
+ int third = *s++ & 0x3f; | |
+ AddUtf8(first | second | third); | |
+ n -= 2; | |
+ start -= 2; | |
+ } | |
+#else | |
+ else | |
PUTCHARLP(*s++); | |
+#endif | |
} | |
} | |
r = winmsg_rend[i]; | |
@@ -3106,8 +3130,32 @@ int start, max; | |
{ | |
if (start-- > 0) | |
s++; | |
- else | |
+#ifdef UTF8 | |
+ else if ((unsigned char)*s < 0x80) | |
+ { | |
+ PUTCHARLP(*s++); | |
+ } | |
+ else if ((unsigned char)*s < 0xe0) | |
+ { | |
+ int first = (*s++ & 0x1f) << 6; | |
+ int second = *s++ & 0x3f; | |
+ AddUtf8(first | second); | |
+ n -= 1; | |
+ start -= 1; | |
+ } | |
+ else /* if (*s2 < 0xf0) */ | |
+ { | |
+ int first = (*s++ & 0x1f) << 12; | |
+ int second = (*s++ & 0x3f) << 6; | |
+ int third = *s++ & 0x3f; | |
+ AddUtf8(first | second | third); | |
+ n -= 2; | |
+ start -= 2; | |
+ } | |
+#else | |
+ else | |
PUTCHARLP(*s++); | |
+#endif | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment