|
6 | 6 | #include "pathspec.h"
|
7 | 7 | #include "color.h"
|
8 | 8 | #include "diff.h"
|
| 9 | +#include "compat/terminal.h" |
9 | 10 |
|
10 | 11 | enum prompt_mode_type {
|
11 | 12 | PROMPT_MODE_CHANGE = 0, PROMPT_DELETION, PROMPT_HUNK
|
@@ -1047,14 +1048,27 @@ static int run_apply_check(struct add_p_state *s,
|
1047 | 1048 | return 0;
|
1048 | 1049 | }
|
1049 | 1050 |
|
| 1051 | +static int read_single_character(struct add_p_state *s) |
| 1052 | +{ |
| 1053 | + if (s->s.use_single_key) { |
| 1054 | + int res = read_key_without_echo(&s->answer); |
| 1055 | + printf("%s\n", res == EOF ? "" : s->answer.buf); |
| 1056 | + return res; |
| 1057 | + } |
| 1058 | + |
| 1059 | + if (strbuf_getline(&s->answer, stdin) == EOF) |
| 1060 | + return EOF; |
| 1061 | + strbuf_trim_trailing_newline(&s->answer); |
| 1062 | + return 0; |
| 1063 | +} |
| 1064 | + |
1050 | 1065 | static int prompt_yesno(struct add_p_state *s, const char *prompt)
|
1051 | 1066 | {
|
1052 | 1067 | for (;;) {
|
1053 | 1068 | color_fprintf(stdout, s->s.prompt_color, "%s", _(prompt));
|
1054 | 1069 | fflush(stdout);
|
1055 |
| - if (strbuf_getline(&s->answer, stdin) == EOF) |
| 1070 | + if (read_single_character(s) == EOF) |
1056 | 1071 | return -1;
|
1057 |
| - strbuf_trim_trailing_newline(&s->answer); |
1058 | 1072 | switch (tolower(s->answer.buf[0])) {
|
1059 | 1073 | case 'n': return 0;
|
1060 | 1074 | case 'y': return 1;
|
@@ -1290,9 +1304,8 @@ static int patch_update_file(struct add_p_state *s,
|
1290 | 1304 | _(s->mode->prompt_mode[prompt_mode_type]),
|
1291 | 1305 | s->buf.buf);
|
1292 | 1306 | fflush(stdout);
|
1293 |
| - if (strbuf_getline(&s->answer, stdin) == EOF) |
| 1307 | + if (read_single_character(s) == EOF) |
1294 | 1308 | break;
|
1295 |
| - strbuf_trim_trailing_newline(&s->answer); |
1296 | 1309 |
|
1297 | 1310 | if (!s->answer.len)
|
1298 | 1311 | continue;
|
|
0 commit comments