fix(cursor): write CSI 6n query to TTY when stdout is redirected - #1062
Open
raphaelvigee wants to merge 1 commit into
Open
fix(cursor): write CSI 6n query to TTY when stdout is redirected#1062raphaelvigee wants to merge 1 commit into
raphaelvigee wants to merge 1 commit into
Conversation
cursor::position() previously wrote the DSR query to stdout. When stdout is piped to another program (e.g. `prog | rev`), the escape sequence was sent to the pipe instead of the terminal, so the terminal never responded and the call hung until timeout. Pick the first available TTY: stdout, then stderr, then /dev/tty. Uses rustix::termios::isatty (or libc::isatty under the libc feature) to stay within MSRV 1.63. Fixes crossterm-rs#652
Author
|
I'm currently using the version 0.29 of the project, if this PR is accepted in principle i will update it to master |
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.
Summary
Fixes #652.
cursor::position()on Unix wrote theESC [ 6 nDevice Status Report query to stdout. When stdout is piped to another program (e.g.prog | rev), the escape sequence went into the pipe instead of the terminal, so the terminal never responded and the call hung until the 2s timeout. The terminal's reply also corrupted the piped output.Change
write_cursor_querypicks the first available TTY for the query, in order:/dev/ttyThe response is already read via
tty_fd(), which falls back to/dev/ttywhen stdin is not a TTY, so the read side already worked — only the write side needed fixing.rustix::termios::isattyis used for the TTY check (orlibc::isattyunder thelibcfeature). No new dependencies. MSRV 1.63 preserved (avoidedstd::io::IsTerminal, stable in 1.70).Test plan
cargo build(default features)cargo build --features libccargo build --no-default-features --features eventscrossterm::cursor::position()with stdout piped torev— confirm the call returns the cursor position instead of corrupting the pipe / timing out.