git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Carlo Marcelo Arenas Belón" <carenas@gmail.com>,
	"Phillip Wood" <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH 2/3] terminal: set VMIN and VTIME in non-canonical mode
Date: Wed, 16 Feb 2022 13:40:49 -0800	[thread overview]
Message-ID: <xmqqpmnmcwwu.fsf@gitster.g> (raw)
In-Reply-To: <02009172e081ab5c4de8e2476c1142f97b41698e.1645008873.git.gitgitgadget@gmail.com> (Phillip Wood via GitGitGadget's message of "Wed, 16 Feb 2022 10:54:31 +0000")

"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> 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.

Makes sense.

>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  compat/terminal.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/compat/terminal.c b/compat/terminal.c
> index 20803badd03..d882dfa06e3 100644
> --- a/compat/terminal.c
> +++ b/compat/terminal.c
> @@ -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;
> +	}

Quite sensible.  I wonder if we can simplify the "are we looking at
an ESC that is the first byte of a multi-byte control sequence?"
logic in the caller by using inter-character delay, but it is
probably better to go one step at a time like this patch does.

>  	if (!tcsetattr(term_fd, TCSAFLUSH, &t))
>  		return 0;
>  
> @@ -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);

Interesting.  So each call to read_key_without_echo() ends up being
a run_command("stty -icanon min 1 time 0") followed by a read
followed by another "stty".

At least while in -icanon mode, VEOF and VEOL do not take effect,
and the potential overlap would not matter.  It really depends on
what happens upon restore.

Do we have similar "let's hope" on the tcsetattr() side, too?

>  		}
>  
>  		if (bits & ENABLE_ECHO_INPUT) {

Thanks.

  reply	other threads:[~2022-02-16 21:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-16 10:54 [PATCH 0/3] a couple of read_key_without_echo() fixes Phillip Wood via GitGitGadget
2022-02-16 10:54 ` [PATCH 1/3] terminal: pop signal handler when terminal is restored Phillip Wood via GitGitGadget
2022-02-16 10:54 ` [PATCH 2/3] terminal: set VMIN and VTIME in non-canonical mode Phillip Wood via GitGitGadget
2022-02-16 21:40   ` Junio C Hamano [this message]
2022-02-17 10:59     ` Phillip Wood
2022-02-16 10:54 ` [PATCH 3/3] add -p: disable stdin buffering when interactive.singlekey is set Phillip Wood via GitGitGadget
2022-02-16 21:43   ` Junio C Hamano
2022-02-22 18:53 ` [PATCH v2 0/4] a couple of read_key_without_echo() fixes Phillip Wood via GitGitGadget
2022-02-22 18:53   ` [PATCH v2 1/4] terminal: always reset terminal when reading without echo Phillip Wood via GitGitGadget
2022-02-22 18:53   ` [PATCH v2 2/4] terminal: pop signal handler when terminal is restored Phillip Wood via GitGitGadget
2022-02-22 18:53   ` [PATCH v2 3/4] terminal: set VMIN and VTIME in non-canonical mode Phillip Wood via GitGitGadget
2022-02-22 18:53   ` [PATCH v2 4/4] add -p: disable stdin buffering when interactive.singlekey is set Phillip Wood via GitGitGadget
2022-02-23 21:34   ` [PATCH v2 0/4] a couple of read_key_without_echo() fixes Junio C Hamano
2022-02-24 14:30     ` Phillip Wood
2022-03-22 20:18       ` Carlo Arenas
2022-03-23  9:03         ` Junio C Hamano
2022-03-24 13:29           ` Johannes Schindelin
2022-03-28 10:51         ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqpmnmcwwu.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).