aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-03-05 12:34:31 +0000
committerRon Yorston <rmy@pobox.com>2023-03-05 12:43:46 +0000
commit8ade494aebe60ea14026d48025a462e6d0b58a7f (patch)
tree55181219752cf8c2efac037d8f2bd26c71baaca4 /libbb
parent9aef4d4d298987437e33bf25bcddd16175148d45 (diff)
downloadbusybox-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 'libbb')
-rw-r--r--libbb/lineedit.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index c4f0c65f1..9bf2f89a5 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -726,7 +726,12 @@ static void input_forward(void)
726#if !ENABLE_PLATFORM_MINGW32 726#if !ENABLE_PLATFORM_MINGW32
727 put_cur_glyph_and_inc_cursor(); 727 put_cur_glyph_and_inc_cursor();
728#else 728#else
729 inc_cursor(); 729 {
730 if (terminal_mode(FALSE) & VT_INPUT)
731 put_cur_glyph_and_inc_cursor();
732 else
733 inc_cursor();
734 }
730#endif 735#endif
731} 736}
732 737
@@ -2579,7 +2584,7 @@ static void sigaction2(int sig, struct sigaction *act)
2579 */ 2584 */
2580int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize) 2585int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize)
2581{ 2586{
2582 int len IF_NOT_PLATFORM_MINGW32(, n); 2587 int len, n;
2583 int timeout; 2588 int timeout;
2584#if ENABLE_FEATURE_TAB_COMPLETION 2589#if ENABLE_FEATURE_TAB_COMPLETION
2585 smallint lastWasTab = 0; 2590 smallint lastWasTab = 0;
@@ -2589,9 +2594,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2589 smallint vi_cmdmode = 0; 2594 smallint vi_cmdmode = 0;
2590#endif 2595#endif
2591 struct termios initial_settings; 2596 struct termios initial_settings;
2592#if !ENABLE_PLATFORM_MINGW32
2593 struct termios new_settings; 2597 struct termios new_settings;
2594#endif
2595 char read_key_buffer[KEYCODE_BUFFER_SIZE]; 2598 char read_key_buffer[KEYCODE_BUFFER_SIZE];
2596 2599
2597 INIT_S(); 2600 INIT_S();
@@ -2600,15 +2603,13 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2600 cmdedit_termw = 80; 2603 cmdedit_termw = 80;
2601 IF_FEATURE_EDITING_VI(delptr = delbuf;) 2604 IF_FEATURE_EDITING_VI(delptr = delbuf;)
2602 2605
2603#if !ENABLE_PLATFORM_MINGW32
2604 n = get_termios_and_make_raw(STDIN_FILENO, &new_settings, &initial_settings, 0 2606 n = get_termios_and_make_raw(STDIN_FILENO, &new_settings, &initial_settings, 0
2605 | TERMIOS_CLEAR_ISIG /* turn off INTR (ctrl-C), QUIT, SUSP */ 2607 | TERMIOS_CLEAR_ISIG /* turn off INTR (ctrl-C), QUIT, SUSP */
2606 ); 2608 );
2609#if !ENABLE_PLATFORM_MINGW32
2607 if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) { 2610 if (n != 0 || (initial_settings.c_lflag & (ECHO|ICANON)) == ICANON) {
2608#else 2611#else
2609 initial_settings.c_cc[VINTR] = CTRL('C'); 2612 if (n != 0 || !isatty(0) || !isatty(1)) {
2610 initial_settings.c_cc[VEOF] = CTRL('D');
2611 if (!isatty(0) || !isatty(1)) {
2612#endif 2613#endif
2613 /* Happens when e.g. stty -echo was run before. 2614 /* Happens when e.g. stty -echo was run before.
2614 * But if ICANON is not set, we don't come here. 2615 * But if ICANON is not set, we don't come here.
@@ -2661,9 +2662,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2661#endif 2662#endif
2662#define command command_must_not_be_used 2663#define command command_must_not_be_used
2663 2664
2664#if !ENABLE_PLATFORM_MINGW32
2665 tcsetattr_stdin_TCSANOW(&new_settings); 2665 tcsetattr_stdin_TCSANOW(&new_settings);
2666#endif
2667 2666
2668#if 0 2667#if 0
2669 for (i = 0; i <= state->max_history; i++) 2668 for (i = 0; i <= state->max_history; i++)
@@ -3150,10 +3149,8 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
3150 free_tab_completion_data(); 3149 free_tab_completion_data();
3151#endif 3150#endif
3152 3151
3153#if !ENABLE_PLATFORM_MINGW32
3154 /* restore initial_settings */ 3152 /* restore initial_settings */
3155 tcsetattr_stdin_TCSANOW(&initial_settings); 3153 tcsetattr_stdin_TCSANOW(&initial_settings);
3156#endif
3157#if ENABLE_FEATURE_EDITING_WINCH 3154#if ENABLE_FEATURE_EDITING_WINCH
3158 /* restore SIGWINCH handler */ 3155 /* restore SIGWINCH handler */
3159 sigaction_set(SIGWINCH, &S.SIGWINCH_handler); 3156 sigaction_set(SIGWINCH, &S.SIGWINCH_handler);