feat: add restlyline
This commit is contained in:
30
src/main.rs
30
src/main.rs
@@ -8,6 +8,8 @@ use futures_util::{StreamExt, SinkExt};
|
|||||||
use tokio_tungstenite::tungstenite::Message;
|
use tokio_tungstenite::tungstenite::Message;
|
||||||
use tokio::sync::mpsc::channel;
|
use tokio::sync::mpsc::channel;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
use rustyline::Editor;
|
||||||
|
use rustyline::error::ReadlineError;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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 {
|
loop {
|
||||||
let next = ws_read.next().await;
|
let next = ws_read.next().await;
|
||||||
match next {
|
match next {
|
||||||
@@ -79,4 +106,7 @@ async fn connect_to_and_loop(url: &Url) -> XResult<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.join().unwrap();
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user