Don't flush terminal input when querying checking window size #2009
+9
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As reported in MidnightCommander/mc#4789,
after Midnight Commander starts a shell, it writes some characters
to the shells stdin, to initialize it.
Since mc doesn't know when shell initialization
(e.g. .bashrc), it doesn't wait for that.
Hence mc's commands race with bashrc.
This surfaces reliably when running fastfetch from .bashrc with a *.png
logo. Writing the logo involves a call to ffDetectTerminalSize(),
which queries /dev/tty.
It first flushes (TCSAFLUSH) the input since a070519 (IO: disallow
input echo, 2024-07-31), which removes the input queued by mc.
Then it reads from the TTY 1024 bytes at a time.
This is also bad because it might swallow key presses
made by the user.
So maybe
only one byte at a time.
Note that with or without TCSAFLUSH,
our query responses might be interspersed with keyboard input.
Though I guess TCSAFLUSH makes this less likely.