feat(cli): use rustyline for cmd entry, which allows for richer editing

This commit is contained in:
Khaïs COLIN 2025-05-04 18:36:43 +02:00
parent 6b49d3ca14
commit 3d4ab2e2e4
4 changed files with 158 additions and 15 deletions

View file

@ -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,
}
}