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>
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 896bbc8..678c4d2 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -151,9 +151,11 @@
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 @@
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 @@
}
#endif
+#if ENABLE_FEATURE_EDITING_WINCH
static void cmdedit_setwidth(void)
{
int new_y;
@@ -2054,6 +2059,7 @@
S.SIGWINCH_count++;
}
}
+#endif
static int lineedit_read_key(char *read_key_buffer, int timeout)
{
@@ -2072,9 +2078,9 @@
*
* 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 @@
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 @@
* in one place.
*/
int32_t ic, ic_raw;
+#if ENABLE_FEATURE_EDITING_WINCH
unsigned count;
count = S.SIGWINCH_count;
@@ -2431,7 +2439,7 @@
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 @@
/* 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;