From 701a8d6783f09597e1c9b386b1e6ba890807854c Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 1 Mar 2018 09:14:07 +0000 Subject: 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. --- configs/mingw32_defconfig | 2 ++ configs/mingw64_defconfig | 2 ++ libbb/Config.src | 5 +++++ 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 CONFIG_FEATURE_TAB_COMPLETION=y CONFIG_FEATURE_USERNAME_COMPLETION=y CONFIG_FEATURE_EDITING_FANCY_PROMPT=y +# CONFIG_FEATURE_EDITING_WINCH is not set # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set # CONFIG_LOCALE_SUPPORT is not set # CONFIG_UNICODE_SUPPORT is not set @@ -1082,6 +1083,7 @@ CONFIG_ASH_NOCONSOLE=y # CONFIG_HUSH is not set # CONFIG_HUSH_BASH_COMPAT is not set # CONFIG_HUSH_BRACE_EXPANSION is not set +# CONFIG_HUSH_LINENO_VAR is not set # CONFIG_HUSH_BASH_SOURCE_CURDIR is not set # CONFIG_HUSH_INTERACTIVE is not set # 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 CONFIG_FEATURE_TAB_COMPLETION=y CONFIG_FEATURE_USERNAME_COMPLETION=y CONFIG_FEATURE_EDITING_FANCY_PROMPT=y +# CONFIG_FEATURE_EDITING_WINCH is not set # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set # CONFIG_LOCALE_SUPPORT is not set # CONFIG_UNICODE_SUPPORT is not set @@ -1082,6 +1083,7 @@ CONFIG_ASH_CMDCMD=y # CONFIG_HUSH is not set # CONFIG_HUSH_BASH_COMPAT is not set # CONFIG_HUSH_BRACE_EXPANSION is not set +# CONFIG_HUSH_LINENO_VAR is not set # CONFIG_HUSH_BASH_SOURCE_CURDIR is not set # CONFIG_HUSH_INTERACTIVE is not set # 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 Setting this option allows for prompts to use things like \w and \$ and escape codes. +config FEATURE_EDITING_WINCH + bool "Enable automatic tracking of window size changes" + default y + depends on FEATURE_EDITING + config FEATURE_EDITING_ASK_TERMINAL bool "Query cursor position from terminal" 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 { unsigned num_matches; #endif +#if ENABLE_FEATURE_EDITING_WINCH unsigned SIGWINCH_saved; volatile unsigned SIGWINCH_count; volatile smallint ok_to_redraw; +#endif #if ENABLE_FEATURE_EDITING_VI # define DELBUFSIZ 128 @@ -165,8 +167,10 @@ struct lineedit_statics { smallint sent_ESC_br6n; #endif +#if ENABLE_FEATURE_EDITING_WINCH /* Largish struct, keeping it last results in smaller code */ struct sigaction SIGWINCH_handler; +#endif }; /* See lineedit_ptr_hack.c */ @@ -2092,6 +2096,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) } #endif +#if ENABLE_FEATURE_EDITING_WINCH static void cmdedit_setwidth(void) { int new_y; @@ -2116,6 +2121,7 @@ static void win_changed(int nsig UNUSED_PARAM) S.SIGWINCH_count++; } } +#endif static int lineedit_read_key(char *read_key_buffer, int timeout) { @@ -2134,9 +2140,9 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) * * Note: read_key sets errno to 0 on success. */ - S.ok_to_redraw = 1; + IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) ic = read_key(STDIN_FILENO, read_key_buffer, timeout); - S.ok_to_redraw = 0; + IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) if (errno) { #if ENABLE_UNICODE_SUPPORT 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 parse_and_put_prompt(prompt); ask_terminal(); +#if ENABLE_FEATURE_EDITING_WINCH /* Install window resize handler (NB: after *all* init is complete) */ S.SIGWINCH_handler.sa_handler = win_changed; S.SIGWINCH_handler.sa_flags = SA_RESTART; sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); - +#endif read_key_buffer[0] = 0; while (1) { /* @@ -2492,6 +2499,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman * in one place. */ int32_t ic, ic_raw; +#if ENABLE_FEATURE_EDITING_WINCH unsigned count; count = S.SIGWINCH_count; @@ -2499,7 +2507,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman S.SIGWINCH_saved = count; cmdedit_setwidth(); } - +#endif ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); #if ENABLE_PLATFORM_MINGW32 /* 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 /* restore initial_settings */ tcsetattr_stdin_TCSANOW(&initial_settings); +#if ENABLE_FEATURE_EDITING_WINCH /* restore SIGWINCH handler */ sigaction_set(SIGWINCH, &S.SIGWINCH_handler); +#endif fflush_all(); len = command_len; -- cgit v1.2.3-55-g6feb