aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2020-04-21 14:34:08 +0200
committerDaniel <kingdread@gmx.de>2020-04-21 14:34:08 +0200
commitab909d2f3a0a59ae1b9a169ec79d4e9ffeddd1e1 (patch)
tree37d5360b3ca2056609bbad3497103b1437b25107
parent0a27adbc0bf3bbbf87fea9e55c00c38f61d55058 (diff)
downloadraidgrep-ab909d2f3a0a59ae1b9a169ec79d4e9ffeddd1e1.tar.gz
raidgrep-ab909d2f3a0a59ae1b9a169ec79d4e9ffeddd1e1.tar.bz2
raidgrep-ab909d2f3a0a59ae1b9a169ec79d4e9ffeddd1e1.zip
use readline/rustyline instead of stdin.read_line
This gives us a history, nicer editing capabilities and the possibility to add completion in the future.
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs10
2 files changed, 5 insertions, 6 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 2d64d51..2825776 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,6 +26,7 @@ dirs = "2.0"
log = { version = "0.4", features = ["std"] }
thiserror = "1.0"
lalrpop-util = "0.18"
+rustyline = "6.1"
[build-dependencies]
lalrpop = { version = "0.18", features = ["lexer"] }
diff --git a/src/main.rs b/src/main.rs
index ff882e5..b6633ac 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,6 +11,7 @@ use chrono::{NaiveDateTime, Weekday};
use colored::Colorize;
use log::debug;
use num_traits::cast::FromPrimitive;
+use rustyline::{error::ReadlineError, Editor};
use structopt::StructOpt;
use walkdir::{DirEntry, WalkDir};
@@ -231,13 +232,10 @@ fn run() -> Result<()> {
}
fn repl(opt: &Opt) -> Result<()> {
- let stdin = std::io::stdin();
+ let mut rl = Editor::<()>::new();
loop {
- print!("Query> ");
- std::io::stdout().flush()?;
- let mut line = String::new();
- stdin.read_line(&mut line)?;
- let line = line.trim();
+ let line = rl.readline("Query> ")?;
+ rl.add_history_entry(&line);
let parsed = build_filter(&line);
match parsed {
Ok(filter) => grep(&opt, &*filter)?,