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