From 4b89d512b1215e7b9d619af03496540d30cbbd1a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 25 Nov 2016 03:41:03 +0100 Subject: ash,hush: make ^C in interactive mode visually much closer to bash behavior Signed-off-by: Denys Vlasenko --- shell/hush.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'shell/hush.c') diff --git a/shell/hush.c b/shell/hush.c index 5b720ce..bcd4dff 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -1756,8 +1756,6 @@ static int check_and_run_traps(void) switch (sig) { case SIGINT: debug_printf_exec("%s: sig:%d default SIGINT handler\n", __func__, sig); - /* Builtin was ^C'ed, make it look prettier: */ - bb_putchar('\n'); G.flag_SIGINT = 1; last_sig = sig; break; @@ -2195,16 +2193,22 @@ static int get_user_input(struct in_str *i) # if ENABLE_FEATURE_EDITING for (;;) { reinit_unicode_for_hush(); - G.flag_SIGINT = 0; + if (G.flag_SIGINT) { + /* There was ^C'ed, make it look prettier: */ + bb_putchar('\n'); + G.flag_SIGINT = 0; + } /* buglet: SIGINT will not make new prompt to appear _at once_, - * only after . (^C will work) */ + * only after . (^C works immediately) */ r = read_line_input(G.line_input_state, prompt_str, G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1, /*timeout*/ -1 ); - /* read_line_input intercepts ^C, "convert" it into SIGINT */ - if (r == 0) + /* read_line_input intercepts ^C, "convert" it to SIGINT */ + if (r == 0) { + write(STDOUT_FILENO, "^C", 2); raise(SIGINT); + } check_and_run_traps(); if (r != 0 && !G.flag_SIGINT) break; @@ -2232,6 +2236,7 @@ static int get_user_input(struct in_str *i) fputs(prompt_str, stdout); } fflush_all(); +//FIXME: here ^C or SIGINT will have effect only after r = fgetc(i->file); /* In !ENABLE_FEATURE_EDITING we don't use read_line_input, * no ^C masking happens during fgetc, no special code for ^C: -- cgit v1.1