feat(cli): use rustyline for cmd entry, which allows for richer editing
This commit is contained in:
parent
6b49d3ca14
commit
3d4ab2e2e4
4 changed files with 158 additions and 15 deletions
21
src/cli.rs
21
src/cli.rs
|
|
@ -1,18 +1,11 @@
|
|||
use rustyline::DefaultEditor;
|
||||
|
||||
pub fn read_input() -> Option<String> {
|
||||
use std::io::{BufRead, Write};
|
||||
let mut rl = DefaultEditor::new().ok()?;
|
||||
|
||||
print!("osdb > ");
|
||||
std::io::stdout().flush().expect("failed to flush stdout");
|
||||
|
||||
let mut input = String::new();
|
||||
let len = std::io::stdin()
|
||||
.lock()
|
||||
.read_line(&mut input)
|
||||
.expect("failed to read input from stdin");
|
||||
|
||||
if len == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(input)
|
||||
let readline = rl.readline("osdb> ");
|
||||
match readline {
|
||||
Ok(line) => Some(line),
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue