diff options
author | Ron Yorston <rmy@pobox.com> | 2023-03-06 12:25:39 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-03-06 12:25:39 +0000 |
commit | b50470de96320425adbed82129bdb7f7f5263ddb (patch) | |
tree | 129ee385d0d9c658eb7f71717372ea496dd604e1 | |
parent | 8ade494aebe60ea14026d48025a462e6d0b58a7f (diff) | |
download | busybox-w32-b50470de96320425adbed82129bdb7f7f5263ddb.tar.gz busybox-w32-b50470de96320425adbed82129bdb7f7f5263ddb.tar.bz2 busybox-w32-b50470de96320425adbed82129bdb7f7f5263ddb.zip |
win32: virtual terminal input fixes
- Disable ENABLE_PROCESSED_INPUT in raw mode. Otherwise ^C isn't
immediately detected during shell command line editing with
virtual terminal input enabled.
- Switch read_key()/unix_readkey() to windows_read_key()/read_key().
This allows the shell `read` builtin to use windows_read_key().
Without this change `read` fails when virtual terminal input is
enabled.
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/read_key.c | 9 | ||||
-rw-r--r-- | libbb/xfuncs.c | 3 | ||||
-rw-r--r-- | shell/shell_common.c | 2 | ||||
-rw-r--r-- | win32/termios.c | 5 |
5 files changed, 10 insertions, 11 deletions
diff --git a/include/libbb.h b/include/libbb.h index c1d4d11c1..4276bae61 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1976,7 +1976,7 @@ enum { | |||
1976 | */ | 1976 | */ |
1977 | int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 1977 | int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
1978 | #if ENABLE_PLATFORM_MINGW32 | 1978 | #if ENABLE_PLATFORM_MINGW32 |
1979 | int64_t unix_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 1979 | int64_t windows_read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
1980 | #endif | 1980 | #endif |
1981 | /* This version loops on EINTR: */ | 1981 | /* This version loops on EINTR: */ |
1982 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 1982 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
diff --git a/libbb/read_key.c b/libbb/read_key.c index c34770028..54886cc9c 100644 --- a/libbb/read_key.c +++ b/libbb/read_key.c | |||
@@ -9,11 +9,7 @@ | |||
9 | */ | 9 | */ |
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | #if ENABLE_PLATFORM_MINGW32 | ||
13 | int64_t FAST_FUNC unix_read_key(int fd, char *buffer, int timeout) | ||
14 | #else | ||
15 | int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | 12 | int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) |
16 | #endif | ||
17 | { | 13 | { |
18 | struct pollfd pfd; | 14 | struct pollfd pfd; |
19 | const char *seq; | 15 | const char *seq; |
@@ -116,6 +112,11 @@ int64_t FAST_FUNC read_key(int fd, char *buffer, int timeout) | |||
116 | 0 | 112 | 0 |
117 | }; | 113 | }; |
118 | 114 | ||
115 | #if ENABLE_PLATFORM_MINGW32 | ||
116 | if (!(terminal_mode(FALSE) & VT_INPUT)) | ||
117 | return windows_read_key(fd, buffer, timeout); | ||
118 | #endif | ||
119 | |||
119 | pfd.fd = fd; | 120 | pfd.fd = fd; |
120 | pfd.events = POLLIN; | 121 | pfd.events = POLLIN; |
121 | 122 | ||
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index bf15f4c75..cbeb24701 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -326,7 +326,8 @@ int FAST_FUNC get_termios_and_make_raw(int fd, struct termios *newterm, struct t | |||
326 | *newterm = *oldterm; | 326 | *newterm = *oldterm; |
327 | 327 | ||
328 | #if ENABLE_PLATFORM_MINGW32 | 328 | #if ENABLE_PLATFORM_MINGW32 |
329 | newterm->imode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT); | 329 | newterm->imode &= |
330 | ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT); | ||
330 | #else | 331 | #else |
331 | /* Turn off buffered input (ICANON) | 332 | /* Turn off buffered input (ICANON) |
332 | * Turn off echoing (ECHO) | 333 | * Turn off echoing (ECHO) |
diff --git a/shell/shell_common.c b/shell/shell_common.c index 9d74dcb7a..efe8828e4 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c | |||
@@ -223,7 +223,7 @@ shell_builtin_read(struct builtin_read_params *params) | |||
223 | if (isatty(fd)) { | 223 | if (isatty(fd)) { |
224 | int64_t key; | 224 | int64_t key; |
225 | 225 | ||
226 | key = read_key(fd, NULL, timeout); | 226 | key = windows_read_key(fd, NULL, timeout); |
227 | if (key == 0x03) { | 227 | if (key == 0x03) { |
228 | /* ^C pressed */ | 228 | /* ^C pressed */ |
229 | retval = (const char *)(uintptr_t)2; | 229 | retval = (const char *)(uintptr_t)2; |
diff --git a/win32/termios.c b/win32/termios.c index 20ec4dcc5..9fa97685d 100644 --- a/win32/termios.c +++ b/win32/termios.c | |||
@@ -28,7 +28,7 @@ int tcgetattr(int fd, struct termios *t) | |||
28 | return 0; | 28 | return 0; |
29 | } | 29 | } |
30 | 30 | ||
31 | int64_t FAST_FUNC read_key(int fd, char *buf, int timeout) | 31 | int64_t FAST_FUNC windows_read_key(int fd, char *buf UNUSED_PARAM, int timeout) |
32 | { | 32 | { |
33 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); | 33 | HANDLE cin = GetStdHandle(STD_INPUT_HANDLE); |
34 | INPUT_RECORD record; | 34 | INPUT_RECORD record; |
@@ -41,9 +41,6 @@ int64_t FAST_FUNC read_key(int fd, char *buf, int timeout) | |||
41 | DWORD alt_pressed = FALSE; | 41 | DWORD alt_pressed = FALSE; |
42 | DWORD state; | 42 | DWORD state; |
43 | 43 | ||
44 | if (terminal_mode(FALSE) & VT_INPUT) | ||
45 | return unix_read_key(fd, buf, timeout); | ||
46 | |||
47 | if (fd != 0) | 44 | if (fd != 0) |
48 | bb_error_msg_and_die("read_key only works on stdin"); | 45 | bb_error_msg_and_die("read_key only works on stdin"); |
49 | if (cin == INVALID_HANDLE_VALUE) | 46 | if (cin == INVALID_HANDLE_VALUE) |