console-rs / console-rs/console
Term.size() always returns size of stdout, even if target is stderr
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.2k
- Forks
- 144
- Avg merge
- 8h 24m
- Merged PRs (30d)
- 4
Description
I'm trying to read the size of the terminal attached to stderr while stdout is redirected to a file.
/path/to/program > out.txt
let term = Term::buffered_stderr();
let size = term.size();
The above code is returning the default terminal size, since terminal_size is calling the isatty on STDOUT_FILENO and returning None. (see unix_term.rs:49)
This is likely a simple fix: Use the raw file descriptor from the Term when checking isatty, instead of hard coding STDOUT_FILENO.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in unix_term.rs:49 and trace how Term::size() selects the file descriptor and checks isatty. Reproduce the stderr case described with stdout redirected, then verify that terminal size lookup uses the terminal attached to Term rather than assuming stdout; add or update a focused test if the repository has an appropriate location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100