diff options
Diffstat (limited to 'win32/winansi.c')
-rw-r--r-- | win32/winansi.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index 479e5ca40..5a6c33350 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -1348,4 +1348,25 @@ BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got) | |||
1348 | *got = 1; | 1348 | *got = 1; |
1349 | return TRUE; | 1349 | return TRUE; |
1350 | } | 1350 | } |
1351 | #else | ||
1352 | /* | ||
1353 | * In Windows 10 and 11 using ReadConsoleInputA() with a console input | ||
1354 | * code page of CP_UTF8 can crash the console/terminal. Avoid this by | ||
1355 | * using ReadConsoleInputW() in that case. | ||
1356 | */ | ||
1357 | BOOL readConsoleInput_utf8(HANDLE h, INPUT_RECORD *r, DWORD len, DWORD *got) | ||
1358 | { | ||
1359 | if (GetConsoleCP() != CP_UTF8) | ||
1360 | return ReadConsoleInput(h, r, len, got); | ||
1361 | |||
1362 | if (ReadConsoleInputW(h, r, len, got)) { | ||
1363 | wchar_t uchar = r->Event.KeyEvent.uChar.UnicodeChar; | ||
1364 | char achar = uchar & 0x7f; | ||
1365 | if (achar != uchar) | ||
1366 | achar = '?'; | ||
1367 | r->Event.KeyEvent.uChar.AsciiChar = achar; | ||
1368 | return TRUE; | ||
1369 | } | ||
1370 | return FALSE; | ||
1371 | } | ||
1351 | #endif | 1372 | #endif |