diff options
author | Marek Polacek <mmpolacek@gmail.com> | 2010-10-28 21:34:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-10-28 21:34:56 +0200 |
commit | 7b18107384d950358e146d42bf02b391fab5ffd6 (patch) | |
tree | 9994e2bcaa038c3128ed8b3bca99486e22f660fb /libbb | |
parent | 02788ac7e2a44eee889aa1005e89076f928e964a (diff) | |
download | busybox-w32-7b18107384d950358e146d42bf02b391fab5ffd6.tar.gz busybox-w32-7b18107384d950358e146d42bf02b391fab5ffd6.tar.bz2 busybox-w32-7b18107384d950358e146d42bf02b391fab5ffd6.zip |
*: use _exit() in sighandlers; showkey: do not use exit-thru-sighandler
While at it, make ESC sequences more readable; and removed check for
isatty(stdin) in reset. Code shrink:
text data bss dec hex filename
884771 936 17216 902923 dc70b busybox_old
884723 936 17216 902875 dc6db busybox_unstripped
Signed-off-by: Marek Polacek <mmpolacek@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/lineedit.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 066b569f6..68006ffba 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -94,8 +94,10 @@ static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); } | |||
94 | #endif | 94 | #endif |
95 | 95 | ||
96 | 96 | ||
97 | #define SEQ_CLEAR_TILL_END_OF_SCREEN "\033[J" | 97 | #define ESC "\033" |
98 | //#define SEQ_CLEAR_TILL_END_OF_LINE "\033[K" | 98 | |
99 | #define SEQ_CLEAR_TILL_END_OF_SCREEN ESC"[J" | ||
100 | //#define SEQ_CLEAR_TILL_END_OF_LINE ESC"[K" | ||
99 | 101 | ||
100 | 102 | ||
101 | enum { | 103 | enum { |
@@ -446,7 +448,7 @@ static void input_backward(unsigned num) | |||
446 | } while (--num); | 448 | } while (--num); |
447 | return; | 449 | return; |
448 | } | 450 | } |
449 | printf("\033[%uD", num); | 451 | printf(ESC"[%uD", num); |
450 | return; | 452 | return; |
451 | } | 453 | } |
452 | 454 | ||
@@ -471,7 +473,7 @@ static void input_backward(unsigned num) | |||
471 | */ | 473 | */ |
472 | unsigned sv_cursor; | 474 | unsigned sv_cursor; |
473 | /* go to 1st column; go up to first line */ | 475 | /* go to 1st column; go up to first line */ |
474 | printf("\r" "\033[%uA", cmdedit_y); | 476 | printf("\r" ESC"[%uA", cmdedit_y); |
475 | cmdedit_y = 0; | 477 | cmdedit_y = 0; |
476 | sv_cursor = cursor; | 478 | sv_cursor = cursor; |
477 | put_prompt(); /* sets cursor to 0 */ | 479 | put_prompt(); /* sets cursor to 0 */ |
@@ -488,12 +490,12 @@ static void input_backward(unsigned num) | |||
488 | cmdedit_x = (width * cmdedit_y - num) % width; | 490 | cmdedit_x = (width * cmdedit_y - num) % width; |
489 | cmdedit_y -= lines_up; | 491 | cmdedit_y -= lines_up; |
490 | /* go to 1st column; go up */ | 492 | /* go to 1st column; go up */ |
491 | printf("\r" "\033[%uA", lines_up); | 493 | printf("\r" ESC"[%uA", lines_up); |
492 | /* go to correct column. | 494 | /* go to correct column. |
493 | * xterm, konsole, Linux VT interpret 0 as 1 below! wow. | 495 | * xterm, konsole, Linux VT interpret 0 as 1 below! wow. |
494 | * need to *make sure* we skip it if cmdedit_x == 0 */ | 496 | * need to *make sure* we skip it if cmdedit_x == 0 */ |
495 | if (cmdedit_x) | 497 | if (cmdedit_x) |
496 | printf("\033[%uC", cmdedit_x); | 498 | printf(ESC"[%uC", cmdedit_x); |
497 | } | 499 | } |
498 | } | 500 | } |
499 | 501 | ||
@@ -501,7 +503,7 @@ static void input_backward(unsigned num) | |||
501 | static void redraw(int y, int back_cursor) | 503 | static void redraw(int y, int back_cursor) |
502 | { | 504 | { |
503 | if (y > 0) /* up y lines */ | 505 | if (y > 0) /* up y lines */ |
504 | printf("\033[%uA", y); | 506 | printf(ESC"[%uA", y); |
505 | bb_putchar('\r'); | 507 | bb_putchar('\r'); |
506 | put_prompt(); | 508 | put_prompt(); |
507 | put_till_end_and_adv_cursor(); | 509 | put_till_end_and_adv_cursor(); |
@@ -1626,7 +1628,7 @@ static void ask_terminal(void) | |||
1626 | pfd.events = POLLIN; | 1628 | pfd.events = POLLIN; |
1627 | if (safe_poll(&pfd, 1, 0) == 0) { | 1629 | if (safe_poll(&pfd, 1, 0) == 0) { |
1628 | S.sent_ESC_br6n = 1; | 1630 | S.sent_ESC_br6n = 1; |
1629 | fputs("\033" "[6n", stdout); | 1631 | fputs(ESC"[6n", stdout); |
1630 | fflush_all(); /* make terminal see it ASAP! */ | 1632 | fflush_all(); /* make terminal see it ASAP! */ |
1631 | } | 1633 | } |
1632 | } | 1634 | } |
@@ -2074,7 +2076,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li | |||
2074 | case CTRL('L'): | 2076 | case CTRL('L'): |
2075 | vi_case(CTRL('L')|VI_CMDMODE_BIT:) | 2077 | vi_case(CTRL('L')|VI_CMDMODE_BIT:) |
2076 | /* Control-l -- clear screen */ | 2078 | /* Control-l -- clear screen */ |
2077 | printf("\033[H"); /* cursor to top,left */ | 2079 | printf(ESC"[H"); /* cursor to top,left */ |
2078 | redraw(0, command_len - cursor); | 2080 | redraw(0, command_len - cursor); |
2079 | break; | 2081 | break; |
2080 | #if MAX_HISTORY > 0 | 2082 | #if MAX_HISTORY > 0 |