diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2023-06-25 01:42:52 +0300 |
---|---|---|
committer | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2023-06-28 18:08:00 +0300 |
commit | 1602a45b797908025dc71e6a07149a39fdb12a48 (patch) | |
tree | b381b12bacfe1fe5acf154e16d6050a34083f540 /libbb | |
parent | ebe80f3e5c9b612f4d1b6e444c9badc10f9f2745 (diff) | |
download | busybox-w32-1602a45b797908025dc71e6a07149a39fdb12a48.tar.gz busybox-w32-1602a45b797908025dc71e6a07149a39fdb12a48.tar.bz2 busybox-w32-1602a45b797908025dc71e6a07149a39fdb12a48.zip |
win32: the great UTF8 ReadConsoleInput hack
Since commit 597d31ee (EURO_INPUT), ReadConsoleInputA is the default.
The main problem with that is that if the console codepage is UTF8,
e.g. after "chcp 65001", then typing or pasting can result in a crash
of the console itself (the Windows Terminal or cmd.exe window closes).
Additionally and regardless of this crash, ReadConsoleInputA is
apparently buggy with UTF8 CP also otherwise.
For instance, on Windows 7 only ASCII values work - others become '?'.
Or sometimes in Windows 10 (cmd.exe console but not Windows terminal)
only key-up events arrive for some non-ASCII codepoints (without
a prior key-down), and more.
So this commit implements readConsoleInput_utf8 which delivers UTF8
Regardless of CP, including of surrogate pairs, and works on win 7/10.
Other than fixing the crash and working much better with UTF8 console
CP, it also allows a build with the UTF8 manifest to capture correctly
arbitrary unicode inputs which are typed or pasted into the console
regardless of the console CP.
However, it doesn't look OK unless the console CP is set to UTF8
(which we don't do automatically, but the user can chcp 65001),
and editing is still lacking due to missing screen-length awareness.
To reproduce the crash: start a new console window, 'chcp 65001', run
this program (or busybox sh), and paste "ಀ" or "😀" (U+0C80, U+1F600)
#include <windows.h>
int main() {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD r;
DWORD n;
while (ReadConsoleInputA(h, &r, 1, &n)) /* NOP */;
return 0;
}
Diffstat (limited to 'libbb')
0 files changed, 0 insertions, 0 deletions