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 /shell/hush.c | |
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>
Diffstat (limited to 'shell/hush.c')
-rw-r--r-- | shell/hush.c | 17 |
1 files changed, 11 insertions, 6 deletions
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: |