ash,hush: make ^C in interactive mode visually much closer to bash behavior
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
24860fa09c
commit
4b89d512b1
@ -2251,6 +2251,7 @@ static int32_t reverse_i_search(void)
|
|||||||
* Returns:
|
* Returns:
|
||||||
* -1 on read errors or EOF, or on bare Ctrl-D,
|
* -1 on read errors or EOF, or on bare Ctrl-D,
|
||||||
* 0 on ctrl-C (the line entered is still returned in 'command'),
|
* 0 on ctrl-C (the line entered is still returned in 'command'),
|
||||||
|
* (in both cases the cursor remains on the input line, '\n' is not printed)
|
||||||
* >0 length of input string, including terminating '\n'
|
* >0 length of input string, including terminating '\n'
|
||||||
*/
|
*/
|
||||||
int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout)
|
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
|
|||||||
&& ic_raw == initial_settings.c_cc[VINTR]
|
&& ic_raw == initial_settings.c_cc[VINTR]
|
||||||
) {
|
) {
|
||||||
/* Ctrl-C (usually) - stop gathering input */
|
/* Ctrl-C (usually) - stop gathering input */
|
||||||
goto_new_line();
|
|
||||||
command_len = 0;
|
command_len = 0;
|
||||||
break_out = -1; /* "do not append '\n'" */
|
break_out = -1; /* "do not append '\n'" */
|
||||||
break;
|
break;
|
||||||
|
@ -9869,7 +9869,8 @@ preadfd(void)
|
|||||||
reinit_unicode_for_ash();
|
reinit_unicode_for_ash();
|
||||||
nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout);
|
nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ, timeout);
|
||||||
if (nr == 0) {
|
if (nr == 0) {
|
||||||
/* Ctrl+C pressed */
|
/* ^C pressed, "convert" to SIGINT */
|
||||||
|
write(STDOUT_FILENO, "^C", 2);
|
||||||
if (trap[SIGINT]) {
|
if (trap[SIGINT]) {
|
||||||
buf[0] = '\n';
|
buf[0] = '\n';
|
||||||
buf[1] = '\0';
|
buf[1] = '\0';
|
||||||
@ -9877,6 +9878,7 @@ preadfd(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
exitstatus = 128 + SIGINT;
|
exitstatus = 128 + SIGINT;
|
||||||
|
bb_putchar('\n');
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
if (nr < 0) {
|
if (nr < 0) {
|
||||||
|
15
shell/hush.c
15
shell/hush.c
@ -1756,8 +1756,6 @@ static int check_and_run_traps(void)
|
|||||||
switch (sig) {
|
switch (sig) {
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
debug_printf_exec("%s: sig:%d default SIGINT handler\n", __func__, sig);
|
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;
|
G.flag_SIGINT = 1;
|
||||||
last_sig = sig;
|
last_sig = sig;
|
||||||
break;
|
break;
|
||||||
@ -2195,16 +2193,22 @@ static int get_user_input(struct in_str *i)
|
|||||||
# if ENABLE_FEATURE_EDITING
|
# if ENABLE_FEATURE_EDITING
|
||||||
for (;;) {
|
for (;;) {
|
||||||
reinit_unicode_for_hush();
|
reinit_unicode_for_hush();
|
||||||
|
if (G.flag_SIGINT) {
|
||||||
|
/* There was ^C'ed, make it look prettier: */
|
||||||
|
bb_putchar('\n');
|
||||||
G.flag_SIGINT = 0;
|
G.flag_SIGINT = 0;
|
||||||
|
}
|
||||||
/* buglet: SIGINT will not make new prompt to appear _at once_,
|
/* buglet: SIGINT will not make new prompt to appear _at once_,
|
||||||
* only after <Enter>. (^C will work) */
|
* only after <Enter>. (^C works immediately) */
|
||||||
r = read_line_input(G.line_input_state, prompt_str,
|
r = read_line_input(G.line_input_state, prompt_str,
|
||||||
G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1,
|
G.user_input_buf, CONFIG_FEATURE_EDITING_MAX_LEN-1,
|
||||||
/*timeout*/ -1
|
/*timeout*/ -1
|
||||||
);
|
);
|
||||||
/* read_line_input intercepts ^C, "convert" it into SIGINT */
|
/* read_line_input intercepts ^C, "convert" it to SIGINT */
|
||||||
if (r == 0)
|
if (r == 0) {
|
||||||
|
write(STDOUT_FILENO, "^C", 2);
|
||||||
raise(SIGINT);
|
raise(SIGINT);
|
||||||
|
}
|
||||||
check_and_run_traps();
|
check_and_run_traps();
|
||||||
if (r != 0 && !G.flag_SIGINT)
|
if (r != 0 && !G.flag_SIGINT)
|
||||||
break;
|
break;
|
||||||
@ -2232,6 +2236,7 @@ static int get_user_input(struct in_str *i)
|
|||||||
fputs(prompt_str, stdout);
|
fputs(prompt_str, stdout);
|
||||||
}
|
}
|
||||||
fflush_all();
|
fflush_all();
|
||||||
|
//FIXME: here ^C or SIGINT will have effect only after <Enter>
|
||||||
r = fgetc(i->file);
|
r = fgetc(i->file);
|
||||||
/* In !ENABLE_FEATURE_EDITING we don't use read_line_input,
|
/* In !ENABLE_FEATURE_EDITING we don't use read_line_input,
|
||||||
* no ^C masking happens during fgetc, no special code for ^C:
|
* no ^C masking happens during fgetc, no special code for ^C:
|
||||||
|
Loading…
Reference in New Issue
Block a user