Term.size() always returns size of stdout, even if target is stderr
ian-mcdowell opened this issue · 1 comments
ian-mcdowell commented
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
.
mitsuhiko commented
As weird as it sounds this was done intentional. I think it requires some rethinking but it's not uncommon that only stdout is connected to a terminal and then the call fails for no reason. Maybe a better solution would be to check either handle? I'm not sure.