console-rs / console-rs/console
Unblocking `read_key()` / writing to stdin
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.2k
- Forks
- 144
- Avg merge
- 8h 24m
- Merged PRs (30d)
- 4
Description
I've been recently writing some async code, and one of the requirements was reading from the consol in raw mode, in a separate thread. Now, this isn't an issue per se:
let console_result = tokio::task::spawn_blocking(move || Term::stdout().read_key()).await?;
Using this code snippet, I can put the blocking read_key() on it's own thread and be happy. Unfortunately, if I need to cancel this operation I don't have a consistent mechanism to do so. Tokio doesn't really allow me to kill the blocking thread directly, or I don't know of a way. There isn't a pretty way to do async console reading/writing - there are some options on windows, but no idea on unix systems.
An alternative would be implementing the functionality to write to stdin. I've made a rough proof-of-conept in a local fork that sends a pre-determined key. A proper system to write to stdin would solve this issue, but does require the implementation of a new feature
Note: my implementation of writing to stdin may not be that stable, but it works for me:
Note: although TIOCSTI was revoked in OpenBSD 6.2 (Oct 2017), apparently the Linux Kernel developers are of the opposite mind, categorically refusing to revoke it (you can read more about this in the OpenBSD Journal).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing Term::stdout().read_key() entry point and the linked proof-of-concept commit for writing a predetermined key to stdin. Clarify platform support, cancellation behavior, and the stability requirements before defining what a supported implementation would need to accomplish.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100