feat: add restlyline

This commit is contained in:
2021-06-13 20:20:27 +08:00
parent 0f33eab15b
commit b717c864ac

View File

@@ -8,6 +8,8 @@ use futures_util::{StreamExt, SinkExt};
use tokio_tungstenite::tungstenite::Message;
use tokio::sync::mpsc::channel;
use url::Url;
use rustyline::Editor;
use rustyline::error::ReadlineError;
#[tokio::main]
async fn main() {
@@ -46,6 +48,31 @@ async fn connect_to_and_loop(url: &Url) -> XResult<()> {
}
});
let t = std::thread::spawn(|| {
let mut rl = Editor::<()>::new();
loop {
let readline = rl.readline("ws $ ");
match readline {
Ok(line) => {
rl.add_history_entry(line.as_str());
println!("Input line: {}", line);
},
Err(ReadlineError::Interrupted) => {
println!("CTRL-C");
break
},
Err(ReadlineError::Eof) => {
println!("CTRL-D");
break
},
Err(err) => {
println!("Error: {:?}", err);
break
}
}
}
});
loop {
let next = ws_read.next().await;
match next {
@@ -79,4 +106,7 @@ async fn connect_to_and_loop(url: &Url) -> XResult<()> {
}
}
}
t.join().unwrap();
Ok(())
}