[PATCH] lineedit: allow window size tracking to be disabled

Ron Yorston rmy at pobox.com
Sun Feb 25 10:42:31 UTC 2018


vi and less have configuration options to allow the use of SIGWINCH
to be configured out.  The line editing code can benefit from a
similar option.

It's enabled by default but when disabled:

function                                             old     new   delta
win_changed                                           54       -     -54
cmdedit_setwidth                                      56       -     -56
read_line_input                                     2655    2589     -66
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/1 up/down: 0/-176)           Total: -176 bytes

Signed-off-by: Ron Yorston <rmy at pobox.com>
---
 libbb/Config.src |  5 +++++
 libbb/lineedit.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)

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..8f1ec2f1e 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -151,8 +151,10 @@ struct lineedit_statics {
 	unsigned num_matches;
 #endif
 
+#if ENABLE_FEATURE_EDITING_WINCH
 	unsigned SIGWINCH_saved;
 	volatile unsigned SIGWINCH_count;
+#endif
 	volatile smallint ok_to_redraw;
 
 #if ENABLE_FEATURE_EDITING_VI
@@ -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)
 {
@@ -2408,10 +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 +2432,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,6 +2440,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);
 
@@ -2868,8 +2878,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;
-- 
2.14.3



More information about the busybox mailing list