From 40217f5588a34d9ddf456307bcd79ce3ef8af2c0 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 1 Jul 2023 12:52:24 +0100 Subject: win32: code shrink readConsoleInput_utf8 Move decision about how to read console input from windows_read_key() to readConsoleInput_utf8(). Saves 48-64 bytes. --- win32/termios.c | 5 +---- win32/winansi.c | 4 ++++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/win32/termios.c b/win32/termios.c index d70c1e685..23184e901 100644 --- a/win32/termios.c +++ b/win32/termios.c @@ -57,10 +57,7 @@ int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout) #if ENABLE_FEATURE_EURO_INPUT if (!ReadConsoleInputW(cin, &record, 1, &nevent_out)) #else - // if ACP is UTF8 then we read UTF8 regardless of console (in) CP - if (GetConsoleCP() == CP_UTF8 || GetACP() == CP_UTF8 - ? !readConsoleInput_utf8(cin, &record, 1, &nevent_out) - : !ReadConsoleInput(cin, &record, 1, &nevent_out)) + if (!readConsoleInput_utf8(cin, &record, 1, &nevent_out)) #endif goto done; diff --git a/win32/winansi.c b/win32/winansi.c index 4beef3eb8..83ce076c0 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -1293,6 +1293,10 @@ BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got) if (len != 1) return FALSE; + // if ACP is UTF8 then we read UTF8 regardless of console (in) CP + if (GetConsoleCP() != CP_UTF8 && GetACP() != CP_UTF8) + return ReadConsoleInput(h, r, len, got); + if (u8pos == u8len) { DWORD codepoint; -- cgit v1.2.3-55-g6feb