-
Notifications
You must be signed in to change notification settings - Fork 176
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
Need ability to specify which file descriptor should be used for input? #599
Comments
I had considered filing a bug for this, but I believe it can be handled on the user's side by using Even if this does work, I think allowing for some configuration of the input file descriptor, or just supporting a toggle to read from |
Thanks, updated src/tty/windows.rs to use "CONIN$" instead of "CON:", and also opened it with both read and write permissions (otherwise was getting a access denied when attempting to call SetConsoleMode()). Did a quick test in a Windows VM, and seems to work.
Agree on this, but unfortunately there also may be some difficulty using freopen, based on this PR: rust-lang/libc#7 . I think that issue is still unresolved based on my searching so far (but I may have missed something also). |
I was able to use |
Could you please give a try to this branch ? let config = Config::builder()
.behavior(Behavior::PreferTerm)
.build();
let mut rl = Editor::with_config(config); echo x | cargo run --example example > debug.log
1> ... Like I still need to fix: https://github.com/gwenn/rustyline/blob/dev_tty/src/tty/windows.rs#L495-L515 (see https://github.com/judah/haskeline/blob/c03e7029b2d9c3d16da5480306b42b8d4ebe03cf/System/Console/Haskeline/Backend/Win32.hsc#L238-L240 or https://github.com/rust-lang/rust/blob/master/library/std/src/sys/windows/stdio.rs#L53-L60) |
Works fine for me on Linux (did not try out Windows). |
Version 10.0.0 released. |
I believe the ability to swap out what FD to use for input is needed in cases where the program using rustyline is having its stdin redirected from a file. In these cases, rustyreadline needs to use a FD still connected to the terminal to read input from, instead of using FD=0...
I was looking at this issue: PaulJuliusMartinez/jless#7 (note that I have no affiliation with this project)
And noticed that src/tty/unix.rs directly refered to STDIN_FILENO, without support for passing in / using another FD (such as a fd pointing to /dev/tty).
This seems to sort of be related to #542 (but this would be a simpler change).
A hacked up version of what this might look like is here: https://github.com/kkawakam/rustyline/compare/master...n1000:configurable_input?expand=1
I'm a Rust beginner, so I mostly worked on this to try and further my learning... The changes above are a hack, but demonstrate the concept. I've realized it's time to go back and reread some parts of "Programming Rust"... :)
It may also be the case that some much simpler solution to this exists, and no change in rustyline is needed...
The text was updated successfully, but these errors were encountered: