Conversation
tuish_init chooses how tuish_has_pending_input peeks the next byte based on whether `read -t0` consumes a byte or only checks availability. It decided this with a heredoc probe — but mksh's own `read -d '' -n 1 -t0` on a heredoc is non-deterministic: it intermittently reports no data even though the heredoc byte is present. When the probe came back empty, tui.sh installed the two-read peek (`_tuish_get_byte -t0 && _tuish_get_byte`). On mksh's tty, however, the first `-t0` read *does* consume a byte, so the second read consumed and stashed a different one — dropping one input byte on every peek that found input. During a glued key burst that silently lost ~4 of 10 events, which is the mksh flakiness seen on CI (e.g. "events: 6" instead of "events: 10" in test_redraw_coalesce). ksh93 and mksh both set KSH_VERSION and both consume on -t0, so select the single-read peek by shell identity instead of probing. bash/busybox do not set KSH_VERSION and their heredoc probe is stable (always reports no data), so they keep the two-read consume path. Verified: heredoc probe under mksh flips between consumed/empty across runs; with the fix, test_redraw_coalesce passes 12/12 under mksh (was ~1-in-3 failing). redraw_coalesce also passes 3/3 under bash, ksh93, busybox; keyboard/characters/special/mouse integration and all unit suites pass under mksh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
tuish_init chooses how tuish_has_pending_input peeks the next byte based on whether
read -t0consumes a byte or only checks availability. It decided this with a heredoc probe — but mksh's ownread -d '' -n 1 -t0on a heredoc is non-deterministic: it intermittently reports no data even though the heredoc byte is present.When the probe came back empty, tui.sh installed the two-read peek (
_tuish_get_byte -t0 && _tuish_get_byte). On mksh's tty, however, the first-t0read does consume a byte, so the second read consumed and stashed a different one — dropping one input byte on every peek that found input. During a glued key burst that silently lost ~4 of 10 events, which is the mksh flakiness seen on CI (e.g. "events: 6" instead of "events: 10" in test_redraw_coalesce).ksh93 and mksh both set KSH_VERSION and both consume on -t0, so select the single-read peek by shell identity instead of probing. bash/busybox do not set KSH_VERSION and their heredoc probe is stable (always reports no data), so they keep the two-read consume path.
Verified: heredoc probe under mksh flips between consumed/empty across runs; with the fix, test_redraw_coalesce passes 12/12 under mksh (was ~1-in-3 failing). redraw_coalesce also passes 3/3 under bash, ksh93, busybox; keyboard/characters/special/mouse integration and all unit suites pass under mksh.