kkawakam / rustyline

Readline Implementation in Rust
https://crates.io/crates/rustyline/
MIT License
1.53k stars 176 forks source link

add support for arbitrary file descriptors on unix #612

Open m-mueller678 opened 2 years ago

m-mueller678 commented 2 years ago

This allows the use of arbitrary file descriptors on unix in response to issue #542. File Descriptors are supplied via a new variant of config::Bhaviour

gwenn commented 2 years ago

Could you please explain why only unix is supported ? And I am afraid that this PR doesn't work for telnet / ssh connection because isatty will return false (jline3 seems to use the system flag to skip isatty check). So I guess we need something more complicated than a file descriptor...

m-mueller678 commented 2 years ago

My main use case for this feature is working with pseudoterminals other than the one controlling the process.

Only Unix is supported because I don't have a Windows machine to work on and don't have any experience with Windows terminal handling. Not for any technical reason.

This does indeed not work well with things other than TTYs. I don't think you can reliably support anything that is not a TTY because you cannot change to raw mode without termios as far as I know. Do you think a flag to override isatty and just assume the user set everything up as needed would be a good idea? If so, Behavior::ArbitraryFileDescriptors seems like a good place to put it. Anyone using this should have to consciously make this choice, and the other behaviours likely don't need it.

As a side note: My current workaround for supporting ssh is to just hijack the pseudo terminal slave. If necessary, I send SIGSTOP to its controlling process to ensure it doesn't steal any of my input.