aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-02-25 20:09:54 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-02-25 20:09:54 +0100
commit23286900da2f38de6b7f0c8318263eac4ce774d1 (patch)
tree5e7bf2e0aa87ac17de2f92adfd2de48683c0abfa /libbb/lineedit.c
parente20a703fd34fa0f3ac17c53d868735a99d794a3e (diff)
downloadbusybox-w32-23286900da2f38de6b7f0c8318263eac4ce774d1.tar.gz
busybox-w32-23286900da2f38de6b7f0c8318263eac4ce774d1.tar.bz2
busybox-w32-23286900da2f38de6b7f0c8318263eac4ce774d1.zip
lineedit: allow window size tracking to be disabled
function old new delta lineedit_read_key 269 261 -8 win_changed 47 - -47 read_line_input 3884 3821 -63 cmdedit_setwidth 63 - -63 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-181) Total: -181 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r--libbb/lineedit.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 896bbc88c..678c4d29c 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 */
@@ -2030,6 +2034,7 @@ static void parse_and_put_prompt(const char *prmt_ptr)
2030} 2034}
2031#endif 2035#endif
2032 2036
2037#if ENABLE_FEATURE_EDITING_WINCH
2033static void cmdedit_setwidth(void) 2038static void cmdedit_setwidth(void)
2034{ 2039{
2035 int new_y; 2040 int new_y;
@@ -2054,6 +2059,7 @@ static void win_changed(int nsig UNUSED_PARAM)
2054 S.SIGWINCH_count++; 2059 S.SIGWINCH_count++;
2055 } 2060 }
2056} 2061}
2062#endif
2057 2063
2058static int lineedit_read_key(char *read_key_buffer, int timeout) 2064static int lineedit_read_key(char *read_key_buffer, int timeout)
2059{ 2065{
@@ -2072,9 +2078,9 @@ static int lineedit_read_key(char *read_key_buffer, int timeout)
2072 * 2078 *
2073 * Note: read_key sets errno to 0 on success. 2079 * Note: read_key sets errno to 0 on success.
2074 */ 2080 */
2075 S.ok_to_redraw = 1; 2081 IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;)
2076 ic = read_key(STDIN_FILENO, read_key_buffer, timeout); 2082 ic = read_key(STDIN_FILENO, read_key_buffer, timeout);
2077 S.ok_to_redraw = 0; 2083 IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;)
2078 if (errno) { 2084 if (errno) {
2079#if ENABLE_UNICODE_SUPPORT 2085#if ENABLE_UNICODE_SUPPORT
2080 if (errno == EAGAIN && unicode_idx != 0) 2086 if (errno == EAGAIN && unicode_idx != 0)
@@ -2408,11 +2414,12 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2408 parse_and_put_prompt(prompt); 2414 parse_and_put_prompt(prompt);
2409 ask_terminal(); 2415 ask_terminal();
2410 2416
2417#if ENABLE_FEATURE_EDITING_WINCH
2411 /* Install window resize handler (NB: after *all* init is complete) */ 2418 /* Install window resize handler (NB: after *all* init is complete) */
2412 S.SIGWINCH_handler.sa_handler = win_changed; 2419 S.SIGWINCH_handler.sa_handler = win_changed;
2413 S.SIGWINCH_handler.sa_flags = SA_RESTART; 2420 S.SIGWINCH_handler.sa_flags = SA_RESTART;
2414 sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); 2421 sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler);
2415 2422#endif
2416 read_key_buffer[0] = 0; 2423 read_key_buffer[0] = 0;
2417 while (1) { 2424 while (1) {
2418 /* 2425 /*
@@ -2424,6 +2431,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2424 * in one place. 2431 * in one place.
2425 */ 2432 */
2426 int32_t ic, ic_raw; 2433 int32_t ic, ic_raw;
2434#if ENABLE_FEATURE_EDITING_WINCH
2427 unsigned count; 2435 unsigned count;
2428 2436
2429 count = S.SIGWINCH_count; 2437 count = S.SIGWINCH_count;
@@ -2431,7 +2439,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2431 S.SIGWINCH_saved = count; 2439 S.SIGWINCH_saved = count;
2432 cmdedit_setwidth(); 2440 cmdedit_setwidth();
2433 } 2441 }
2434 2442#endif
2435 ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); 2443 ic = ic_raw = lineedit_read_key(read_key_buffer, timeout);
2436 2444
2437#if ENABLE_FEATURE_REVERSE_SEARCH 2445#if ENABLE_FEATURE_REVERSE_SEARCH
@@ -2868,8 +2876,10 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2868 2876
2869 /* restore initial_settings */ 2877 /* restore initial_settings */
2870 tcsetattr_stdin_TCSANOW(&initial_settings); 2878 tcsetattr_stdin_TCSANOW(&initial_settings);
2879#if ENABLE_FEATURE_EDITING_WINCH
2871 /* restore SIGWINCH handler */ 2880 /* restore SIGWINCH handler */
2872 sigaction_set(SIGWINCH, &S.SIGWINCH_handler); 2881 sigaction_set(SIGWINCH, &S.SIGWINCH_handler);
2882#endif
2873 fflush_all(); 2883 fflush_all();
2874 2884
2875 len = command_len; 2885 len = command_len;