|
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,
|
@@ -1149,14 +1150,27 @@ static int run_apply_check(struct add_p_state *s,
|
1149 | 1150 | return 0;
|
1150 | 1151 | }
|
1151 | 1152 |
|
| 1153 | +static int read_single_character(struct add_p_state *s) |
| 1154 | +{ |
| 1155 | + if (s->s.use_single_key) { |
| 1156 | + int res = read_key_without_echo(&s->answer); |
| 1157 | + printf("%s\n", res == EOF ? "" : s->answer.buf); |
| 1158 | + return res; |
| 1159 | + } |
| 1160 | + |
| 1161 | + if (strbuf_getline(&s->answer, stdin) == EOF) |
| 1162 | + return EOF; |
| 1163 | + strbuf_trim_trailing_newline(&s->answer); |
| 1164 | + return 0; |
| 1165 | +} |
| 1166 | + |
1152 | 1167 | static int prompt_yesno(struct add_p_state *s, const char *prompt)
|
1153 | 1168 | {
|
1154 | 1169 | for (;;) {
|
1155 | 1170 | color_fprintf(stdout, s->s.prompt_color, "%s", _(prompt));
|
1156 | 1171 | fflush(stdout);
|
1157 |
| - if (strbuf_getline(&s->answer, stdin) == EOF) |
| 1172 | + if (read_single_character(s) == EOF) |
1158 | 1173 | return -1;
|
1159 |
| - strbuf_trim_trailing_newline(&s->answer); |
1160 | 1174 | switch (tolower(s->answer.buf[0])) {
|
1161 | 1175 | case 'n': return 0;
|
1162 | 1176 | case 'y': return 1;
|
@@ -1396,9 +1410,8 @@ static int patch_update_file(struct add_p_state *s,
|
1396 | 1410 | _(s->mode->prompt_mode[prompt_mode_type]),
|
1397 | 1411 | s->buf.buf);
|
1398 | 1412 | fflush(stdout);
|
1399 |
| - if (strbuf_getline(&s->answer, stdin) == EOF) |
| 1413 | + if (read_single_character(s) == EOF) |
1400 | 1414 | break;
|
1401 |
| - strbuf_trim_trailing_newline(&s->answer); |
1402 | 1415 |
|
1403 | 1416 | if (!s->answer.len)
|
1404 | 1417 | continue;
|
|
0 commit comments