Skip to content

Commit

Permalink
terminal: set VMIN and VTIME in non-canonical mode
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
phillipwood authored and gitster committed Feb 23, 2022
1 parent f7da756 commit 2c68602
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compat/terminal.c
Expand Up @@ -57,6 +57,10 @@ static int disable_bits(tcflag_t bits)
t = old_term;

t.c_lflag &= ~bits;
if (bits & ICANON) {
t.c_cc[VMIN] = 1;
t.c_cc[VTIME] = 0;
}
if (!tcsetattr(term_fd, TCSAFLUSH, &t))
return 0;

Expand Down Expand Up @@ -159,7 +163,11 @@ static int disable_bits(DWORD bits)

if (bits & ENABLE_LINE_INPUT) {
string_list_append(&stty_restore, "icanon");
strvec_push(&cp.args, "-icanon");
/*
* POSIX allows VMIN and VTIME to overlap with VEOF and
* VEOL - let's hope that is not the case on windows.
*/
strvec_pushl(&cp.args, "-icanon", "min", "1", "time", "0", NULL);
}

if (bits & ENABLE_ECHO_INPUT) {
Expand Down

0 comments on commit 2c68602

Please sign in to comment.