added rustyline support

This commit is contained in:
2023-06-26 17:26:21 -06:00
parent de185ab8a6
commit 7b24173bbd
3 changed files with 302 additions and 7 deletions

View File

@@ -18,11 +18,16 @@
use std::{
env::args,
io::{ BufRead, BufReader, stdin, Write },
io::{ BufRead, BufReader, Write },
net::TcpStream,
thread,
};
use rustyline::{
DefaultEditor,
error::ReadlineError,
};
use yacexits::exit;
fn main() {
@@ -54,7 +59,7 @@ fn main() {
let words: Vec<&str> = message.split_whitespace().collect();
match words[0] {
"FROM" => print!("{}: ", words[1..].join(" ")),
"BODY" => println!("{}", words[1..].join(" ")),
"BODY" => println!("\x1B[1A\r{}", words[1..].join(" ")),
_ => {},
}
}
@@ -62,9 +67,18 @@ fn main() {
});
loop {
let mut buf = String::new();
let _ = stdin().read_line(&mut buf);
let out = format!("BODY {}\n", buf);
let _ = stream.write(out.as_bytes());
let mut e = DefaultEditor::new().unwrap();
let read = e.readline(&format!("{}: ", user));
match read {
Ok(contents) => {
let out = format!("BODY {}\n", contents);
let _ = stream.write(out.as_bytes());
},
Err(ReadlineError::Eof) => break,
Err(ReadlineError::Interrupted) => break,
Err(err) => {
eprintln!("{}: {}", argv[0], err);
},
};
}
}