diff options
| author | Ron Yorston <rmy@pobox.com> | 2023-03-05 12:34:31 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2023-03-05 12:43:46 +0000 |
| commit | 8ade494aebe60ea14026d48025a462e6d0b58a7f (patch) | |
| tree | 55181219752cf8c2efac037d8f2bd26c71baaca4 /miscutils | |
| parent | 9aef4d4d298987437e33bf25bcddd16175148d45 (diff) | |
| download | busybox-w32-8ade494aebe60ea14026d48025a462e6d0b58a7f.tar.gz busybox-w32-8ade494aebe60ea14026d48025a462e6d0b58a7f.tar.bz2 busybox-w32-8ade494aebe60ea14026d48025a462e6d0b58a7f.zip | |
win32: add support for virtual terminal input
Alter certain applets to support virtual terminal input, if enabled.
In many places this is achieved by building previously excluded
upstream terminal-handling code. The busybox-w32 implementation
of termios(3) functions does nothing if virtual terminal input is
disabled, so it can be invoked regardless.
Some applet-specific terminal-handling code is also required.
This affects less, more, vi and command line editing in the shell.
(The `more` applet isn't enabled in the default configuration.)
This series of patches adds about 1.7KB to the binaries.
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/less.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 842031ca3..467c76e2a 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
| @@ -240,9 +240,7 @@ struct globals { | |||
| 240 | smallint winsize_err; | 240 | smallint winsize_err; |
| 241 | #endif | 241 | #endif |
| 242 | smallint terminated; | 242 | smallint terminated; |
| 243 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 244 | struct termios term_orig, term_less; | 243 | struct termios term_orig, term_less; |
| 245 | #endif | ||
| 246 | char kbd_input[KEYCODE_BUFFER_SIZE]; | 244 | char kbd_input[KEYCODE_BUFFER_SIZE]; |
| 247 | }; | 245 | }; |
| 248 | #define G (*ptr_to_globals) | 246 | #define G (*ptr_to_globals) |
| @@ -304,9 +302,7 @@ struct globals { | |||
| 304 | static void set_tty_cooked(void) | 302 | static void set_tty_cooked(void) |
| 305 | { | 303 | { |
| 306 | fflush_all(); | 304 | fflush_all(); |
| 307 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 308 | tcsetattr(kbd_fd, TCSANOW, &term_orig); | 305 | tcsetattr(kbd_fd, TCSANOW, &term_orig); |
| 309 | #endif | ||
| 310 | } | 306 | } |
| 311 | 307 | ||
| 312 | /* Move the cursor to a position (x,y), where (0,0) is the | 308 | /* Move the cursor to a position (x,y), where (0,0) is the |
| @@ -1132,8 +1128,11 @@ static void reinitialize(void) | |||
| 1132 | buffer_fill_and_print(); | 1128 | buffer_fill_and_print(); |
| 1133 | } | 1129 | } |
| 1134 | 1130 | ||
| 1135 | #if !ENABLE_PLATFORM_MINGW32 | 1131 | #if ENABLE_PLATFORM_MINGW32 |
| 1132 | static int64_t unix_getch_nowait(void) | ||
| 1133 | #else | ||
| 1136 | static int64_t getch_nowait(void) | 1134 | static int64_t getch_nowait(void) |
| 1135 | #endif | ||
| 1137 | { | 1136 | { |
| 1138 | int rd; | 1137 | int rd; |
| 1139 | int64_t key64; | 1138 | int64_t key64; |
| @@ -1194,11 +1193,15 @@ static int64_t getch_nowait(void) | |||
| 1194 | set_tty_cooked(); | 1193 | set_tty_cooked(); |
| 1195 | return key64; | 1194 | return key64; |
| 1196 | } | 1195 | } |
| 1197 | #else | 1196 | |
| 1197 | #if ENABLE_PLATFORM_MINGW32 | ||
| 1198 | static int64_t getch_nowait(void) | 1198 | static int64_t getch_nowait(void) |
| 1199 | { | 1199 | { |
| 1200 | int64_t c; | 1200 | int64_t c; |
| 1201 | 1201 | ||
| 1202 | if (terminal_mode(FALSE) & VT_INPUT) | ||
| 1203 | return unix_getch_nowait(); | ||
| 1204 | |||
| 1202 | retry: | 1205 | retry: |
| 1203 | c = _getch(); | 1206 | c = _getch(); |
| 1204 | if (c == 0 || c == 0xe0) { | 1207 | if (c == 0 || c == 0xe0) { |
| @@ -1894,6 +1897,8 @@ int less_main(int argc, char **argv) | |||
| 1894 | { | 1897 | { |
| 1895 | #if !ENABLE_PLATFORM_MINGW32 | 1898 | #if !ENABLE_PLATFORM_MINGW32 |
| 1896 | char *tty_name; | 1899 | char *tty_name; |
| 1900 | #else | ||
| 1901 | HANDLE h; | ||
| 1897 | #endif | 1902 | #endif |
| 1898 | int tty_fd; | 1903 | int tty_fd; |
| 1899 | 1904 | ||
| @@ -1980,12 +1985,16 @@ int less_main(int argc, char **argv) | |||
| 1980 | G.kbd_fd_orig_flags = ndelay_on(tty_fd); | 1985 | G.kbd_fd_orig_flags = ndelay_on(tty_fd); |
| 1981 | kbd_fd = tty_fd; /* save in a global */ | 1986 | kbd_fd = tty_fd; /* save in a global */ |
| 1982 | #else | 1987 | #else |
| 1983 | kbd_fd = tty_fd = 0; | 1988 | h = CreateFileA("CONIN$", GENERIC_READ | GENERIC_WRITE, |
| 1989 | FILE_SHARE_READ, NULL, OPEN_EXISTING, | ||
| 1990 | FILE_ATTRIBUTE_NORMAL, NULL); | ||
| 1991 | if (h == INVALID_HANDLE_VALUE) | ||
| 1992 | bb_simple_error_msg_and_die("unable to open console"); | ||
| 1993 | |||
| 1994 | kbd_fd = tty_fd = _open_osfhandle((intptr_t)h, O_BINARY); | ||
| 1984 | #endif | 1995 | #endif |
| 1985 | 1996 | ||
| 1986 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1987 | get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL_INPUT); | 1997 | get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL_INPUT); |
| 1988 | #endif | ||
| 1989 | 1998 | ||
| 1990 | IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line); | 1999 | IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line); |
| 1991 | /* 20: two tabstops + 4 */ | 2000 | /* 20: two tabstops + 4 */ |
