-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e106086
commit f2f45ed
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::thread; | ||
|
||
use rustyline::error::ReadlineError; | ||
use rustyline::Editor; | ||
|
||
use futures::future::Future; | ||
use futures::stream::Stream; | ||
|
||
use tokio::sync::mpsc; | ||
|
||
fn main() { | ||
let (mut stdin_tx, stdin_rx) = mpsc::unbounded_channel(); | ||
let (mut stdout_tx, stdout_rx) = mpsc::unbounded_channel(); | ||
|
||
let mut editor = Editor::<()>::new(); | ||
|
||
let thread = thread::spawn(move || loop { | ||
let line = editor.readline(">"); | ||
match &line { | ||
Err(ReadlineError::Interrupted) => break, | ||
Err(ReadlineError::Eof) => break, | ||
_ => (), | ||
} | ||
stdin_tx.try_send(line); | ||
}); | ||
|
||
let read_all = stdin_rx.for_each(move |line| { | ||
let message = match line { | ||
Ok(line) => format!("Line: {}", line), | ||
Err(ReadlineError::Interrupted) => format!("CTRL-C"), | ||
Err(ReadlineError::Eof) => format!("CTRL-D"), | ||
Err(err) => format!("Error: {:?}", err), | ||
}; | ||
stdout_tx.try_send(message); | ||
|
||
Ok(()) | ||
}); | ||
|
||
tokio::run(read_all.map_err(|_| ())); | ||
} |