ref: 30f853b65820280931e06e07fd5f624313670305
parent: d3cb02d8105b78408e22a115c1abe80a2743d0f5
author: Simon Howard <[email protected]>
date: Wed Dec 21 10:11:22 EST 2016
textscreen: Fix input of Unicode characters. For non-ASCII characters we map into a higher range to avoid conflict with special keys. Restore this behavior.
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -61,6 +61,11 @@
( (x) < 128 ? (x) : \
(x) >= TXT_UNICODE_BASE ? ((x) - TXT_UNICODE_BASE + 128) : 0 )
+// Convert a Unicode character to a key value:
+
+#define TXT_UNICODE_TO_KEY(u) \
+ ( (u) < 128 ? (u) : ((u) - 128 + TXT_UNICODE_BASE) )
+
// Screen size
#define TXT_SCREEN_W 80
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -671,7 +671,10 @@
{
// TODO: Support input of more than just the first char?
const char *p = ev.text.text;
- return TXT_DecodeUTF8(&p);
+ int result = TXT_DecodeUTF8(&p);
+ // 0-127 is ASCII, but we map non-ASCII Unicode chars into
+ // a higher range to avoid conflicts with special keys.
+ return TXT_UNICODE_TO_KEY(result);
}
break;