diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-01 09:14:07 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-01 09:14:07 +0000 |
commit | 701a8d6783f09597e1c9b386b1e6ba890807854c (patch) | |
tree | a09ba427ac46258d7e5ddc6ddd482dbeaa4721b6 | |
parent | 9427d06e8813a3bf0a9ef4a5b964e0206a083294 (diff) | |
download | busybox-w32-701a8d6783f09597e1c9b386b1e6ba890807854c.tar.gz busybox-w32-701a8d6783f09597e1c9b386b1e6ba890807854c.tar.bz2 busybox-w32-701a8d6783f09597e1c9b386b1e6ba890807854c.zip |
lineedit: disable window size tracking in default configuration
SIGWINCH isn't available on Microsoft Windows. Make the use of
SIGWINCH configurable and disable it by default.
-rw-r--r-- | configs/mingw32_defconfig | 2 | ||||
-rw-r--r-- | configs/mingw64_defconfig | 2 | ||||
-rw-r--r-- | libbb/Config.src | 5 | ||||
-rw-r--r-- | libbb/lineedit.c | 18 |
4 files changed, 23 insertions, 4 deletions
diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index 7c56866a2..265b184f9 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig | |||
@@ -103,6 +103,7 @@ CONFIG_FEATURE_REVERSE_SEARCH=y | |||
103 | CONFIG_FEATURE_TAB_COMPLETION=y | 103 | CONFIG_FEATURE_TAB_COMPLETION=y |
104 | CONFIG_FEATURE_USERNAME_COMPLETION=y | 104 | CONFIG_FEATURE_USERNAME_COMPLETION=y |
105 | CONFIG_FEATURE_EDITING_FANCY_PROMPT=y | 105 | CONFIG_FEATURE_EDITING_FANCY_PROMPT=y |
106 | # CONFIG_FEATURE_EDITING_WINCH is not set | ||
106 | # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set | 107 | # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set |
107 | # CONFIG_LOCALE_SUPPORT is not set | 108 | # CONFIG_LOCALE_SUPPORT is not set |
108 | # CONFIG_UNICODE_SUPPORT is not set | 109 | # CONFIG_UNICODE_SUPPORT is not set |
@@ -1082,6 +1083,7 @@ CONFIG_ASH_NOCONSOLE=y | |||
1082 | # CONFIG_HUSH is not set | 1083 | # CONFIG_HUSH is not set |
1083 | # CONFIG_HUSH_BASH_COMPAT is not set | 1084 | # CONFIG_HUSH_BASH_COMPAT is not set |
1084 | # CONFIG_HUSH_BRACE_EXPANSION is not set | 1085 | # CONFIG_HUSH_BRACE_EXPANSION is not set |
1086 | # CONFIG_HUSH_LINENO_VAR is not set | ||
1085 | # CONFIG_HUSH_BASH_SOURCE_CURDIR is not set | 1087 | # CONFIG_HUSH_BASH_SOURCE_CURDIR is not set |
1086 | # CONFIG_HUSH_INTERACTIVE is not set | 1088 | # CONFIG_HUSH_INTERACTIVE is not set |
1087 | # CONFIG_HUSH_SAVEHISTORY is not set | 1089 | # CONFIG_HUSH_SAVEHISTORY is not set |
diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 3261d17b8..aa355ae66 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig | |||
@@ -103,6 +103,7 @@ CONFIG_FEATURE_REVERSE_SEARCH=y | |||
103 | CONFIG_FEATURE_TAB_COMPLETION=y | 103 | CONFIG_FEATURE_TAB_COMPLETION=y |
104 | CONFIG_FEATURE_USERNAME_COMPLETION=y | 104 | CONFIG_FEATURE_USERNAME_COMPLETION=y |
105 | CONFIG_FEATURE_EDITING_FANCY_PROMPT=y | 105 | CONFIG_FEATURE_EDITING_FANCY_PROMPT=y |
106 | # CONFIG_FEATURE_EDITING_WINCH is not set | ||
106 | # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set | 107 | # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set |
107 | # CONFIG_LOCALE_SUPPORT is not set | 108 | # CONFIG_LOCALE_SUPPORT is not set |
108 | # CONFIG_UNICODE_SUPPORT is not set | 109 | # CONFIG_UNICODE_SUPPORT is not set |
@@ -1082,6 +1083,7 @@ CONFIG_ASH_CMDCMD=y | |||
1082 | # CONFIG_HUSH is not set | 1083 | # CONFIG_HUSH is not set |
1083 | # CONFIG_HUSH_BASH_COMPAT is not set | 1084 | # CONFIG_HUSH_BASH_COMPAT is not set |
1084 | # CONFIG_HUSH_BRACE_EXPANSION is not set | 1085 | # CONFIG_HUSH_BRACE_EXPANSION is not set |
1086 | # CONFIG_HUSH_LINENO_VAR is not set | ||
1085 | # CONFIG_HUSH_BASH_SOURCE_CURDIR is not set | 1087 | # CONFIG_HUSH_BASH_SOURCE_CURDIR is not set |
1086 | # CONFIG_HUSH_INTERACTIVE is not set | 1088 | # CONFIG_HUSH_INTERACTIVE is not set |
1087 | # CONFIG_HUSH_SAVEHISTORY is not set | 1089 | # CONFIG_HUSH_SAVEHISTORY is not set |
diff --git a/libbb/Config.src b/libbb/Config.src index 3c1b064b6..fdf8bbb28 100644 --- a/libbb/Config.src +++ b/libbb/Config.src | |||
@@ -149,6 +149,11 @@ config FEATURE_EDITING_FANCY_PROMPT | |||
149 | Setting this option allows for prompts to use things like \w and | 149 | Setting this option allows for prompts to use things like \w and |
150 | \$ and escape codes. | 150 | \$ and escape codes. |
151 | 151 | ||
152 | config FEATURE_EDITING_WINCH | ||
153 | bool "Enable automatic tracking of window size changes" | ||
154 | default y | ||
155 | depends on FEATURE_EDITING | ||
156 | |||
152 | config FEATURE_EDITING_ASK_TERMINAL | 157 | config FEATURE_EDITING_ASK_TERMINAL |
153 | bool "Query cursor position from terminal" | 158 | bool "Query cursor position from terminal" |
154 | default n | 159 | default n |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index f22f5768f..b9ba71242 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -151,9 +151,11 @@ struct lineedit_statics { | |||
151 | unsigned num_matches; | 151 | unsigned num_matches; |
152 | #endif | 152 | #endif |
153 | 153 | ||
154 | #if ENABLE_FEATURE_EDITING_WINCH | ||
154 | unsigned SIGWINCH_saved; | 155 | unsigned SIGWINCH_saved; |
155 | volatile unsigned SIGWINCH_count; | 156 | volatile unsigned SIGWINCH_count; |
156 | volatile smallint ok_to_redraw; | 157 | volatile smallint ok_to_redraw; |
158 | #endif | ||
157 | 159 | ||
158 | #if ENABLE_FEATURE_EDITING_VI | 160 | #if ENABLE_FEATURE_EDITING_VI |
159 | # define DELBUFSIZ 128 | 161 | # define DELBUFSIZ 128 |
@@ -165,8 +167,10 @@ struct lineedit_statics { | |||
165 | smallint sent_ESC_br6n; | 167 | smallint sent_ESC_br6n; |
166 | #endif | 168 | #endif |
167 | 169 | ||
170 | #if ENABLE_FEATURE_EDITING_WINCH | ||
168 | /* Largish struct, keeping it last results in smaller code */ | 171 | /* Largish struct, keeping it last results in smaller code */ |
169 | struct sigaction SIGWINCH_handler; | 172 | struct sigaction SIGWINCH_handler; |
173 | #endif | ||
170 | }; | 174 | }; |
171 | 175 | ||
172 | /* See lineedit_ptr_hack.c */ | 176 | /* See lineedit_ptr_hack.c */ |
@@ -2092,6 +2096,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
2092 | } | 2096 | } |
2093 | #endif | 2097 | #endif |
2094 | 2098 | ||
2099 | #if ENABLE_FEATURE_EDITING_WINCH | ||
2095 | static void cmdedit_setwidth(void) | 2100 | static void cmdedit_setwidth(void) |
2096 | { | 2101 | { |
2097 | int new_y; | 2102 | int new_y; |
@@ -2116,6 +2121,7 @@ static void win_changed(int nsig UNUSED_PARAM) | |||
2116 | S.SIGWINCH_count++; | 2121 | S.SIGWINCH_count++; |
2117 | } | 2122 | } |
2118 | } | 2123 | } |
2124 | #endif | ||
2119 | 2125 | ||
2120 | static int lineedit_read_key(char *read_key_buffer, int timeout) | 2126 | static int lineedit_read_key(char *read_key_buffer, int timeout) |
2121 | { | 2127 | { |
@@ -2134,9 +2140,9 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) | |||
2134 | * | 2140 | * |
2135 | * Note: read_key sets errno to 0 on success. | 2141 | * Note: read_key sets errno to 0 on success. |
2136 | */ | 2142 | */ |
2137 | S.ok_to_redraw = 1; | 2143 | IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) |
2138 | ic = read_key(STDIN_FILENO, read_key_buffer, timeout); | 2144 | ic = read_key(STDIN_FILENO, read_key_buffer, timeout); |
2139 | S.ok_to_redraw = 0; | 2145 | IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) |
2140 | if (errno) { | 2146 | if (errno) { |
2141 | #if ENABLE_UNICODE_SUPPORT | 2147 | #if ENABLE_UNICODE_SUPPORT |
2142 | if (errno == EAGAIN && unicode_idx != 0) | 2148 | if (errno == EAGAIN && unicode_idx != 0) |
@@ -2476,11 +2482,12 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2476 | parse_and_put_prompt(prompt); | 2482 | parse_and_put_prompt(prompt); |
2477 | ask_terminal(); | 2483 | ask_terminal(); |
2478 | 2484 | ||
2485 | #if ENABLE_FEATURE_EDITING_WINCH | ||
2479 | /* Install window resize handler (NB: after *all* init is complete) */ | 2486 | /* Install window resize handler (NB: after *all* init is complete) */ |
2480 | S.SIGWINCH_handler.sa_handler = win_changed; | 2487 | S.SIGWINCH_handler.sa_handler = win_changed; |
2481 | S.SIGWINCH_handler.sa_flags = SA_RESTART; | 2488 | S.SIGWINCH_handler.sa_flags = SA_RESTART; |
2482 | sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); | 2489 | sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); |
2483 | 2490 | #endif | |
2484 | read_key_buffer[0] = 0; | 2491 | read_key_buffer[0] = 0; |
2485 | while (1) { | 2492 | while (1) { |
2486 | /* | 2493 | /* |
@@ -2492,6 +2499,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2492 | * in one place. | 2499 | * in one place. |
2493 | */ | 2500 | */ |
2494 | int32_t ic, ic_raw; | 2501 | int32_t ic, ic_raw; |
2502 | #if ENABLE_FEATURE_EDITING_WINCH | ||
2495 | unsigned count; | 2503 | unsigned count; |
2496 | 2504 | ||
2497 | count = S.SIGWINCH_count; | 2505 | count = S.SIGWINCH_count; |
@@ -2499,7 +2507,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2499 | S.SIGWINCH_saved = count; | 2507 | S.SIGWINCH_saved = count; |
2500 | cmdedit_setwidth(); | 2508 | cmdedit_setwidth(); |
2501 | } | 2509 | } |
2502 | 2510 | #endif | |
2503 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); | 2511 | ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); |
2504 | #if ENABLE_PLATFORM_MINGW32 | 2512 | #if ENABLE_PLATFORM_MINGW32 |
2505 | /* scroll to cursor position on any keypress */ | 2513 | /* scroll to cursor position on any keypress */ |
@@ -2941,8 +2949,10 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2941 | 2949 | ||
2942 | /* restore initial_settings */ | 2950 | /* restore initial_settings */ |
2943 | tcsetattr_stdin_TCSANOW(&initial_settings); | 2951 | tcsetattr_stdin_TCSANOW(&initial_settings); |
2952 | #if ENABLE_FEATURE_EDITING_WINCH | ||
2944 | /* restore SIGWINCH handler */ | 2953 | /* restore SIGWINCH handler */ |
2945 | sigaction_set(SIGWINCH, &S.SIGWINCH_handler); | 2954 | sigaction_set(SIGWINCH, &S.SIGWINCH_handler); |
2955 | #endif | ||
2946 | fflush_all(); | 2956 | fflush_all(); |
2947 | 2957 | ||
2948 | len = command_len; | 2958 | len = command_len; |