-
Notifications
You must be signed in to change notification settings - Fork 287
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
fix: fall back to /dev/tty when stdin/stdin is not a tty #957
base: master
Are you sure you want to change the base?
Conversation
This might fix an issue I have in skim-rs/skim#653 |
Hey @LoricAndre, I'm not sure when this will be reviewed. If you want to give this branch a try, it would be helpful to see if it does fix your issue since the original problem that skim was facing (#396) is one of the main reasons I made this change. |
Changing from processing input from stdin to always using dev/tty seems like it would fundamentally change the behavior of apps. I'm not certain that this is desired in all cases. Can you talk a bit about the impact of the change and perhaps discuss where this might not be desired? A good way to think about this is put yourself in the perspective of an app developer who sees this change. What does it mean for their app? What does it mean if they hit a problem caused by this change? |
Input processing currently uses the The only scenario I can think of where explicitly reading from It wouldn't be too difficult to have another method or some conditional logic that prefers |
My question is not so much about whether the use case is rational, but more about whether by choosing this approach is a one way door. I.e. this change makes it impossible to use stdin instead of tty as the input. An example of where you might want to do this is nesting an inner TUI app inside an outer one and using the stdin / out as the means to control the inner tty from the outer. |
Fair point. I suppose it doesn't hurt to prefer using |
4e9fd94
to
74f0826
Compare
Actually, I don't think it matters here. If you're piping input from a parent process, |
Resolves #919
Resolves #396
Supersedes #743
Previous attempts to read from
/dev/tty
had issues because of problems with polling/dev/tty
on MacOS. This has been solved for a while with theuse-dev-tty
feature, so now it should be safe to fall back to using/dev/tty
ifstdin
/stdout
is not a terminal everywhere except for the mio event reader on MacOS.This PR standardizes the use of
/dev/tty
for both input and output by splitting thetty_fd
function intotty_fd_in
andtty_fd_out
so both can handle the appropriate fallback logic forstdin
andstdout
respectively. The only place that needs special care is the MacOS event reader whenuse-dev-tty
is not enabled.The mio event reader for MacOS has been modified to return an explicit error message when used with piped input to inform users that
use-dev-tty
is required for such use cases. The error message was previously getting swallowed, but will now be returned to the caller.Finally, the logic to read the cursor position was always writing to
stdout
, causing an error whenstdout
was not a tty. This has been changed to use the newtty_fd_out
function.This was tested on Mac, Linux, and WSL. Windows should be unaffected.