aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-11-28 01:10:16 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-11-28 01:10:16 +0100
commit038a977d47c99c3e59d7a2393799b2afa838604c (patch)
treee10b303c2b43ad808a3d9d5ace3cab3307350a92
parent2c769c69b269f43d8c9ecf4a7f5ce5cce290750a (diff)
downloadbusybox-w32-038a977d47c99c3e59d7a2393799b2afa838604c.tar.gz
busybox-w32-038a977d47c99c3e59d7a2393799b2afa838604c.tar.bz2
busybox-w32-038a977d47c99c3e59d7a2393799b2afa838604c.zip
lineedit: simplify code a bit
function old new delta lineedit_read_key 155 162 +7 put_prompt 51 46 -5 read_line_input 3722 3715 -7 cmdedit_setwidth 81 50 -31 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 7/-43) Total: -36 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/lineedit.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 7a1b5433d..31e392147 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -440,7 +440,6 @@ static void beep(void)
440static void put_prompt(void) 440static void put_prompt(void)
441{ 441{
442 fputs(cmdedit_prompt, stdout); 442 fputs(cmdedit_prompt, stdout);
443 fflush_all();
444 cursor = 0; 443 cursor = 0;
445 cmdedit_y = cmdedit_prmt_len / cmdedit_termw; /* new quasireal y */ 444 cmdedit_y = cmdedit_prmt_len / cmdedit_termw; /* new quasireal y */
446 cmdedit_x = cmdedit_prmt_len % cmdedit_termw; 445 cmdedit_x = cmdedit_prmt_len % cmdedit_termw;
@@ -1978,16 +1977,15 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1978} 1977}
1979#endif 1978#endif
1980 1979
1981static void cmdedit_setwidth(int redraw_flg) 1980static void cmdedit_setwidth(void)
1982{ 1981{
1983 get_terminal_width_height(STDIN_FILENO, &cmdedit_termw, NULL); 1982 int new_y;
1984 if (redraw_flg) { 1983
1985 /* new y for current cursor */ 1984 cmdedit_termw = get_terminal_width(STDIN_FILENO);
1986 int new_y = (cursor + cmdedit_prmt_len) / cmdedit_termw; 1985 /* new y for current cursor */
1987 /* redraw */ 1986 new_y = (cursor + cmdedit_prmt_len) / cmdedit_termw;
1988 redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor); 1987 /* redraw */
1989 fflush_all(); 1988 redraw((new_y >= cmdedit_y ? new_y : cmdedit_y), command_len - cursor);
1990 }
1991} 1989}
1992 1990
1993static void win_changed(int nsig UNUSED_PARAM) 1991static void win_changed(int nsig UNUSED_PARAM)
@@ -1995,7 +1993,8 @@ static void win_changed(int nsig UNUSED_PARAM)
1995 if (S.ok_to_redraw) { 1993 if (S.ok_to_redraw) {
1996 /* We are in read_key(), safe to redraw immediately */ 1994 /* We are in read_key(), safe to redraw immediately */
1997 int sv_errno = errno; 1995 int sv_errno = errno;
1998 cmdedit_setwidth(/*redraw_flg:*/ 1); 1996 cmdedit_setwidth();
1997 fflush_all();
1999 errno = sv_errno; 1998 errno = sv_errno;
2000 } else { 1999 } else {
2001 /* Signal main loop that redraw is necessary */ 2000 /* Signal main loop that redraw is necessary */
@@ -2011,6 +2010,7 @@ static int lineedit_read_key(char *read_key_buffer, int timeout)
2011 int unicode_idx = 0; 2010 int unicode_idx = 0;
2012#endif 2011#endif
2013 2012
2013 fflush_all();
2014 while (1) { 2014 while (1) {
2015 /* Wait for input. TIMEOUT = -1 makes read_key wait even 2015 /* Wait for input. TIMEOUT = -1 makes read_key wait even
2016 * on nonblocking stdin, TIMEOUT = 50 makes sure we won't 2016 * on nonblocking stdin, TIMEOUT = 50 makes sure we won't
@@ -2152,7 +2152,6 @@ static int32_t reverse_i_search(void)
2152 int h; 2152 int h;
2153 unsigned match_buf_len = strlen(match_buf); 2153 unsigned match_buf_len = strlen(match_buf);
2154 2154
2155 fflush_all();
2156//FIXME: correct timeout? 2155//FIXME: correct timeout?
2157 ic = lineedit_read_key(read_key_buffer, -1); 2156 ic = lineedit_read_key(read_key_buffer, -1);
2158 2157
@@ -2282,7 +2281,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2282 * tty is still in "raw mode"). 2281 * tty is still in "raw mode").
2283 */ 2282 */
2284 parse_and_put_prompt(prompt); 2283 parse_and_put_prompt(prompt);
2285 /* fflush_all(); - done by parse_and_put_prompt */ 2284 fflush_all();
2286 if (fgets(command, maxsize, stdin) == NULL) 2285 if (fgets(command, maxsize, stdin) == NULL)
2287 len = -1; /* EOF or error */ 2286 len = -1; /* EOF or error */
2288 else 2287 else
@@ -2362,7 +2361,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2362 S.SIGWINCH_handler.sa_flags = SA_RESTART; 2361 S.SIGWINCH_handler.sa_flags = SA_RESTART;
2363 sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); 2362 sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler);
2364 2363
2365 cmdedit_setwidth(/*redraw_flg:*/ 0); /* get initial window size */ 2364 cmdedit_termw = get_terminal_width(STDIN_FILENO);
2366 2365
2367 read_key_buffer[0] = 0; 2366 read_key_buffer[0] = 0;
2368 while (1) { 2367 while (1) {
@@ -2380,10 +2379,9 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2380 count = S.SIGWINCH_count; 2379 count = S.SIGWINCH_count;
2381 if (S.SIGWINCH_saved != count) { 2380 if (S.SIGWINCH_saved != count) {
2382 S.SIGWINCH_saved = count; 2381 S.SIGWINCH_saved = count;
2383 cmdedit_setwidth(/*redraw_flg:*/ 1); 2382 cmdedit_setwidth();
2384 } 2383 }
2385 2384
2386 fflush_all();
2387 ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); 2385 ic = ic_raw = lineedit_read_key(read_key_buffer, timeout);
2388 2386
2389#if ENABLE_FEATURE_REVERSE_SEARCH 2387#if ENABLE_FEATURE_REVERSE_SEARCH