aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Config.src5
-rw-r--r--libbb/lineedit.c18
2 files changed, 19 insertions, 4 deletions
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 896bbc88c..678c4d29c 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 */
@@ -2030,6 +2034,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;
@@ -2054,6 +2059,7 @@ static void win_changed(int nsig UNUSED_PARAM)
S.SIGWINCH_count++;
}
}
+#endif
static int lineedit_read_key(char *read_key_buffer, int timeout)
{
@@ -2072,9 +2078,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)
@@ -2408,11 +2414,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) {
/*
@@ -2424,6 +2431,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;
@@ -2431,7 +2439,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_FEATURE_REVERSE_SEARCH
@@ -2868,8 +2876,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;