diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-25 03:41:03 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-25 03:41:03 +0100 |
commit | 4b89d512b1215e7b9d619af03496540d30cbbd1a (patch) | |
tree | 166830c57d912e78dfac591c4e47a5cd80cb886e | |
parent | 24860fa09cf954704232406055d7ca291c636eab (diff) | |
download | busybox-w32-4b89d512b1215e7b9d619af03496540d30cbbd1a.tar.gz busybox-w32-4b89d512b1215e7b9d619af03496540d30cbbd1a.tar.bz2 busybox-w32-4b89d512b1215e7b9d619af03496540d30cbbd1a.zip |
ash,hush: make ^C in interactive mode visually much closer to bash behavior
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/lineedit.c | 2 | ||||
-rw-r--r-- | shell/ash.c | 4 | ||||
-rw-r--r-- | shell/hush.c | 17 |
3 files changed, 15 insertions, 8 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index ac049f57d..4d7828cfa 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -2251,6 +2251,7 @@ static int32_t reverse_i_search(void) | |||
2251 | * Returns: | 2251 | * Returns: |
2252 | * -1 on read errors or EOF, or on bare Ctrl-D, | 2252 | * -1 on read errors or EOF, or on bare Ctrl-D, |
2253 | * 0 on ctrl-C (the line entered is still returned in 'command'), | 2253 | * 0 on ctrl-C (the line entered is still returned in 'command'), |
2254 | * (in both cases the cursor remains on the input line, '\n' is not printed) | ||
2254 | * >0 length of input string, including terminating '\n' | 2255 | * >0 length of input string, including terminating '\n' |
2255 | */ | 2256 | */ |
2256 | int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) | 2257 | int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) |
@@ -2686,7 +2687,6 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2686 | && ic_raw == initial_settings.c_cc[VINTR] | 2687 | && ic_raw == initial_settings.c_cc[VINTR] |
2687 | ) { | 2688 | ) { |
2688 | /* Ctrl-C (usually) - stop gathering input */ | 2689 | /* Ctrl-C (usually) - stop gathering input */ |
2689 | goto_new_line(); | ||
2690 | command_len = 0; | 2690 | command_len = 0; |
2691 | break_out = -1; /* "do not append '\n'" */ | 2691 | break_out = -1; /* "do not append '\n'" */ |
2692 | break; | 2692 | break; |
diff --git a/shell/ash.c b/shell/ash.c index 3e5a3b3e9..2bdb4aad7 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -9869,7 +9869,8 @@ preadfd(void) | |||
9869 | reinit_unicode_for_ash(); | 9869 | reinit_unicode_for_ash(); |
9870 | nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); | 9870 | nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout); |
9871 | if (nr == 0) { | 9871 | if (nr == 0) { |
9872 | /* Ctrl+C pressed */ | 9872 | /* ^C pressed, "convert" to SIGINT */ |
9873 | write(STDOUT_FILENO, "^C", 2); | ||
9873 | if (trap[SIGINT]) { | 9874 | if (trap[SIGINT]) { |
9874 | buf[0] = '\n'; | 9875 | buf[0] = '\n'; |
9875 | buf[1] = '\0'; | 9876 | buf[1] = '\0'; |
@@ -9877,6 +9878,7 @@ preadfd(void) | |||
9877 | return 1; | 9878 | return 1; |
9878 | } | 9879 | } |
9879 | exitstatus = 128 + SIGINT; | 9880 | exitstatus = 128 + SIGINT; |
9881 | bb_putchar('\n'); | ||
9880 | goto retry; | 9882 | goto retry; |
9881 | } | 9883 | } |
9882 | if (nr < 0) { | 9884 | if (nr < 0) { |
diff --git a/shell/hush.c b/shell/hush.c index 5b720ce98..bcd4dffee 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1756,8 +1756,6 @@ static int check_and_run_traps(void) | |||
1756 | switch (sig) { | 1756 | switch (sig) { |
1757 | case SIGINT: | 1757 | case SIGINT: |
1758 | debug_printf_exec("%s: sig:%d default SIGINT handler\n", __func__, sig); | 1758 | debug_printf_exec("%s: sig:%d default SIGINT handler\n", __func__, sig); |
1759 | /* Builtin was ^C'ed, make it look prettier: */ | ||
1760 | bb_putchar('\n'); | ||
1761 | G.flag_SIGINT = 1; | 1759 | G.flag_SIGINT = 1; |
1762 | last_sig = sig; | 1760 | last_sig = sig; |
1763 | break; | 1761 | break; |
@@ -2195,16 +2193,22 @@ static int get_user_input(struct in_str *i) | |||
2195 | # if ENABLE_FEATURE_EDITING | 2193 | # if ENABLE_FEATURE_EDITING |
2196 | for (;;) { | 2194 | for (;;) { |
2197 | reinit_unicode_for_hush(); | 2195 | reinit_unicode_for_hush(); |
2198 | G.flag_SIGINT = 0; | 2196 | if (G.flag_SIGINT) { |
2197 | /* There was ^C'ed, make it look prettier: */ | ||
2198 | bb_putchar('\n'); | ||
2199 | G.flag_SIGINT = 0; | ||
2200 | } | ||
2199 | /* buglet: SIGINT will not make new prompt to appear _at once_, | 2201 | /* buglet: SIGINT will not make new prompt to appear _at once_, |
2200 | * only after <Enter>. (^C will work) */ | 2202 | * only after <Enter>. (^C works immediately) */ |
2201 | r = read_line_input(G.line_input_state, prompt_str, | 2203 | r = read_line_input(G.line_input_state, prompt_str, |
2202 | G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1, | 2204 | G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1, |
2203 | /*timeout*/ -1 | 2205 | /*timeout*/ -1 |
2204 | ); | 2206 | ); |
2205 | /* read_line_input intercepts ^C, "convert" it into SIGINT */ | 2207 | /* read_line_input intercepts ^C, "convert" it to SIGINT */ |
2206 | if (r == 0) | 2208 | if (r == 0) { |
2209 | write(STDOUT_FILENO, "^C", 2); | ||
2207 | raise(SIGINT); | 2210 | raise(SIGINT); |
2211 | } | ||
2208 | check_and_run_traps(); | 2212 | check_and_run_traps(); |
2209 | if (r != 0 && !G.flag_SIGINT) | 2213 | if (r != 0 && !G.flag_SIGINT) |
2210 | break; | 2214 | break; |
@@ -2232,6 +2236,7 @@ static int get_user_input(struct in_str *i) | |||
2232 | fputs(prompt_str, stdout); | 2236 | fputs(prompt_str, stdout); |
2233 | } | 2237 | } |
2234 | fflush_all(); | 2238 | fflush_all(); |
2239 | //FIXME: here ^C or SIGINT will have effect only after <Enter> | ||
2235 | r = fgetc(i->file); | 2240 | r = fgetc(i->file); |
2236 | /* In !ENABLE_FEATURE_EDITING we don't use read_line_input, | 2241 | /* In !ENABLE_FEATURE_EDITING we don't use read_line_input, |
2237 | * no ^C masking happens during fgetc, no special code for ^C: | 2242 | * no ^C masking happens during fgetc, no special code for ^C: |