From b5248881cd0d0bd6aa49fdef742d847aed6866b6 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 1 Jul 2023 12:52:24 +0100 Subject: win32: revert to previous console input method by default Although the input method used for euro support is no longer required for that reason it does provide a more lightweight workaround for the problem with ReadConsoleInputA and UTF8. Repurpose FEATURE_EURO_INPUT as FEATURE_UTF8_INPUT. --- Config.in | 13 +++++++------ win32/termios.c | 8 ++++---- win32/winansi.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Config.in b/Config.in index b815b7bd0..33f90fa42 100644 --- a/Config.in +++ b/Config.in @@ -438,6 +438,7 @@ config FEATURE_UTF8_MANIFEST depends on FEATURE_RESOURCES help Include a manifest which sets the process code page to UTF-8. + Users who enable this may also wish to enable FEATURE_UTF8_INPUT. config FEATURE_ICON bool "Include application icon in binary" @@ -473,14 +474,14 @@ config FEATURE_EURO requires the OEM code page to be 858. If the OEM code page of the console is 850 when BusyBox starts it's changed to 858. -config FEATURE_EURO_INPUT - bool "Allow euro on input, even in code pages without euro support" +config FEATURE_UTF8_INPUT + bool "Allow UTF8 console input (0.8 kb)" default n - depends on PLATFORM_MINGW32 && FEATURE_EURO + depends on PLATFORM_MINGW32 help - Allow the euro character to be entered in the console even if the - current code page doesn't support it. It isn't necessary to - enable this setting if the code page in use has euro support. + Allow characters entered in the console to be encoded as UTF8. + This may be useful in conjunction with the UTF8 manifest which + is supported in Window 10 and 11. config TERMINAL_MODE int "Default setting for terminal mode" diff --git a/win32/termios.c b/win32/termios.c index 23184e901..7d6adaafe 100644 --- a/win32/termios.c +++ b/win32/termios.c @@ -34,7 +34,7 @@ int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout) INPUT_RECORD record; DWORD nevent_out, mode; int ret = -1; -#if ENABLE_FEATURE_EURO_INPUT +#if !ENABLE_FEATURE_UTF8_INPUT wchar_t uchar; char achar; #endif @@ -54,7 +54,7 @@ int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout) if (WaitForSingleObject(cin, timeout) != WAIT_OBJECT_0) goto done; } -#if ENABLE_FEATURE_EURO_INPUT +#if !ENABLE_FEATURE_UTF8_INPUT if (!ReadConsoleInputW(cin, &record, 1, &nevent_out)) #else if (!readConsoleInput_utf8(cin, &record, 1, &nevent_out)) @@ -73,7 +73,7 @@ int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout) } alt_pressed = state & LEFT_ALT_PRESSED; -#if ENABLE_FEATURE_EURO_INPUT +#if !ENABLE_FEATURE_UTF8_INPUT if (!record.Event.KeyEvent.uChar.UnicodeChar) { #else if (!record.Event.KeyEvent.uChar.AsciiChar) { @@ -119,7 +119,7 @@ int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout) ret &= ~0x80; goto done; } -#if ENABLE_FEATURE_EURO_INPUT +#if !ENABLE_FEATURE_UTF8_INPUT uchar = record.Event.KeyEvent.uChar.UnicodeChar; achar = uchar & 0x7f; if (achar != uchar) diff --git a/win32/winansi.c b/win32/winansi.c index 83ce076c0..479e5ca40 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -749,8 +749,12 @@ BOOL conToCharBuffA(LPSTR s, DWORD len) CPINFO acp_info, con_info; WCHAR *buf; - // if acp is UTF8 then we got UTF8 via readConsoleInput_utf8 - if (acp == conicp || acp == CP_UTF8) + if (acp == conicp +#if ENABLE_FEATURE_UTF8_INPUT + // if acp is UTF8 then we got UTF8 via readConsoleInput_utf8 + || acp == CP_UTF8 +#endif + ) return TRUE; if (!s || !GetCPInfo(acp, &acp_info) || !GetCPInfo(conicp, &con_info) || @@ -1173,6 +1177,7 @@ int mingw_isatty(int fd) return result; } +#if ENABLE_FEATURE_UTF8_INPUT // intentionally also converts invalid values (surrogate halfs, too big) static int toutf8(DWORD cp, unsigned char *buf) { if (cp <= 0x7f) { @@ -1343,3 +1348,4 @@ BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got) *got = 1; return TRUE; } +#endif -- cgit v1.2.3-55-g6feb