Repository navigation
fix(last): read keys from the terminal after --stdin consumed stdin - #167
Merged
Merged
Conversation
With stdin redirected, crossterm registers /dev/tty with mio, which kqueue on macOS refuses; its keyboard-protocol query then retries the failed poll forever, so the screen stayed blank at full CPU. Once the document is read, put the terminal's own device (named from stdout or stderr) on stdin.
This was referenced Nov 20, 2026
Merged
Merged
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.
Cause
On macOS,
plannotator-tui last --stdin < fileshowed an empty alternate screen and used 100% of a CPU forever. Reproduced on main in a private tmux with a scratchHOME;sampleputs the spin incrossterm::terminal::supports_keyboard_enhancement, called fromcli::with_terminalbefore the first draw:mio) opens/dev/ttyand registers it with kqueue. macOS refuses that, so the event reader has no source.query_keyboard_enhancement_flags_rawloops onpoll_internaland ignores errors (Err(_) => {}), so the immediate "Failed to initialize input reader" error turns into a busy loop. Even without that query, no key could ever be read.Linux's epoll accepts
/dev/tty, so this is macOS-only as far as I can tell (Linux not verified here).Fix
After
last --stdinhas read the document, open the terminal's own device anddup2it onto stdin. The device is named byttynameof stdout or stderr (for example/dev/ttys003);/dev/ttyis the fallback when neither is a terminal. kqueue accepts the real device. crossterm, the hang-up watcher and the keyboard query then all take the ordinary "stdin is a terminal" path. This adds thefsfeature to the existingrustixdependency, whichttynameneeds. No new crates.The other fix, crossterm's
use-dev-ttyfeature, would switch input handling for the whole build, which thediffs-rscomment inCargo.tomlalready avoids.Verified
HOMEandPLANNOTATOR_DATA_DIR: main stays blank at ~99% CPU. With this branch the document draws, CPU is 0%,Ggoes toblock 62/62, andqexits 0.cargo fmt --check,cargo clippy --locked --workspace --all-targets -- -D warningsandcargo test --locked --workspacepass on macOS.No automated test: it would have to replace the test process's own stdin with a pty.