crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.28k stars 281 forks source link

Provide a way to allow running crossterm based applications where stdin and stdout can be retargetted #940

Closed mjgarton closed 1 week ago

mjgarton commented 1 week ago

I have a crossterm based application that I'd like to be able to run in settings other than directly running in a terminal. One example of this is running as a server based application that users can connect to via ssh.

I have used russh ( https://docs.rs/russh/latest/russh/ ) for ssh with other projects, but I find it hard to combine crossterm with russh, because crossterm "hard codes" stdin as the input stream.

Output is not really a problem, since most (perhaps all) crossterm write operations work with any std::io::Write impl. To make read work currently, I have to modify my application to ignore crossterm events and instead handle input directly from the ssh channel itself. I'm looking for a way to avoid this, so my crossterm applications could be modified to run with russh much more easily.

If there were some way in crossterm to specify a replacement for the stdin to use, that might work. Alternatively, a way to "fake" the crossterm events seems reasonable too.