terminal: set VMIN and VTIME in non-canonical mode

If VMIN and VTIME are both set to zero then the terminal performs non-blocking reads which means that read_key_without_echo() returns EOF if there is no key press pending. This results in the user being unable to select anything when running "git add -p". Fix this by explicitly setting VMIN and VTIME when enabling non-canonical mode. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Feb 22, 2022 at 18:53 UTC 2c6860211f211dfa5625dd1a5a69a802b4384dbb
1 file changed +9 -1
compat/terminal.c
+9 -1
@@ -57,6 +57,10 @@ static int disable_bits(tcflag_t bits)
57 t = old_term;
58
59 t.c_lflag &= ~bits;
60 + if (bits & ICANON) {
61 + t.c_cc[VMIN] = 1;
62 + t.c_cc[VTIME] = 0;
63 + }
64 if (!tcsetattr(term_fd, TCSAFLUSH, &t))
65 return 0;
66
@@ -159,7 +163,11 @@ static int disable_bits(DWORD bits)
163
164 if (bits & ENABLE_LINE_INPUT) {
165 string_list_append(&stty_restore, "icanon");
162 - strvec_push(&cp.args, "-icanon");
166 + /*
167 + * POSIX allows VMIN and VTIME to overlap with VEOF and
168 + * VEOL - let's hope that is not the case on windows.
169 + */
170 + strvec_pushl(&cp.args, "-icanon", "min", "1", "time", "0", NULL);
171 }
172
173 if (bits & ENABLE_ECHO_INPUT) {