Skip to content
/ git Public
forked from git/git

Commit 2c68602

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7da756 commit 2c68602

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compat/terminal.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ static int disable_bits(tcflag_t bits)
5757
t = old_term;
5858

5959
t.c_lflag &= ~bits;
60+
if (bits & ICANON) {
61+
t.c_cc[VMIN] = 1;
62+
t.c_cc[VTIME] = 0;
63+
}
6064
if (!tcsetattr(term_fd, TCSAFLUSH, &t))
6165
return 0;
6266

@@ -159,7 +163,11 @@ static int disable_bits(DWORD bits)
159163

160164
if (bits & ENABLE_LINE_INPUT) {
161165
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);
163171
}
164172

165173
if (bits & ENABLE_ECHO_INPUT) {

0 commit comments

Comments
 (0)