Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Term.size() always returns size of stdout, even if target is stderr #174

Open
ian-mcdowell opened this issue May 29, 2023 · 1 comment
Open

Comments

@ian-mcdowell
Copy link

ian-mcdowell commented May 29, 2023

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
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants