mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Avoid console input behavior in windows 10 [Bug #18588]
When ANSI versions of PeekConsoleInput read multibyte charactor partially, subsequent ReadFile returns wrong data on newer Windows 10 versions (probably since Windows Terminal introduced). To avoid this, use Unicode version of of PeekConsoleInput/ReadConsole.
This commit is contained in:
parent
48f1e8c5d8
commit
5d90c60109
Notes:
git
2022-03-16 10:28:56 +09:00
Merged: https://github.com/ruby/ruby/pull/5634 Merged-By: nobu <nobu@ruby-lang.org>
1 changed files with 3 additions and 3 deletions
|
@ -3085,7 +3085,7 @@ is_console(SOCKET sock) /* DONT call this for SOCKET! */
|
|||
INPUT_RECORD ir;
|
||||
|
||||
RUBY_CRITICAL {
|
||||
ret = (PeekConsoleInput((HANDLE)sock, &ir, 1, &n));
|
||||
ret = (PeekConsoleInputW((HANDLE)sock, &ir, 1, &n));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -3100,13 +3100,13 @@ is_readable_console(SOCKET sock) /* call this for console only */
|
|||
INPUT_RECORD ir;
|
||||
|
||||
RUBY_CRITICAL {
|
||||
if (PeekConsoleInput((HANDLE)sock, &ir, 1, &n) && n > 0) {
|
||||
if (PeekConsoleInputW((HANDLE)sock, &ir, 1, &n) && n > 0) {
|
||||
if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
|
||||
ir.Event.KeyEvent.uChar.AsciiChar) {
|
||||
ret = 1;
|
||||
}
|
||||
else {
|
||||
ReadConsoleInput((HANDLE)sock, &ir, 1, &n);
|
||||
ReadConsoleInputW((HANDLE)sock, &ir, 1, &n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue