Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: query terminal properties on ZLE startup



On Thu, Feb 27, 2025 at 12:52 AM Oliver Kiddle <opk@xxxxxxx> wrote:
>
> Out of interest, what do you query the terminal for? Anything I
> didn't cover in the patch?

In my zsh startup files, I'm querying the current cursor position so
that I can place the prompt at the bottom without scrolling the
existing TTY content.

Regarding timeouts, tmux also queries the terminal on startup.
Initially, it had a 1-second timeout, which was later increased to 3
seconds (tmux github issue #2984) and then to 5 seconds (commit
c767d62). If the terminal responds after the timeout has already
triggered, the response is passed to the user process--typically a
shell--causing a mess. I've seen this happen with a 1-second timeout.

Another issue to watch for is buffered input that is sent to the TTY
before zsh starts. A simple test:

1. Run: sh -c 'sleep 5; zsh -f'
2. While sleep is running, paste the following:

   echo $$
   exit
   echo $$

3. Wait for sh to exit.

With an unpatched zsh, this works as expected: the first `echo $$`
prints the PID of the child shell, and the second prints the PID of
the parent. However, with the patched zsh, the second `echo $$` does
not execute.

As far as I understand, there is no robust way to query the terminal
without risking unintended changes to user-visible TTY input and
output. Because of this, I think it's important to have a way to
configure the timeout, and, more importantly, to disable TTY querying
entirely.

Your point about graceful degradation on timeout is well taken. That
said, I'd still prefer an infinite timeout since all my terminals do
respond to queries. On a poor connection, things are already difficult
enough, and dealing with a degraded shell environment would only make
it worse. Given that some terminals don't respond to any queries (I
trust your assessment on this), an infinite timeout likely isn't a
sensible default.

Roman




Messages sorted by: Reverse Date, Date, Thread, Author