aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index fd3399b..5b6d57f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,9 @@
#![feature(trait_alias)]
use std::collections::HashMap;
use std::fmt;
-use std::fs::File;
+use std::fs::{self, File};
use std::io::{BufReader, Read, Seek};
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::atomic::{AtomicBool, Ordering};
@@ -25,6 +25,10 @@ use filters::{log::LogFilter, Inclusion};
mod guilds;
mod logger;
mod output;
+mod paths;
+
+/// Application name, as it should be used in configuration directory paths.
+const APP_NAME: &str = "raidgrep";
/// A program that allows you to search through all your evtc logs for specific people.
///
@@ -299,9 +303,18 @@ fn repl(opt: &Opt) -> Result<()> {
.expect("Could not set interrupt hanlder");
let mut rl = Editor::<()>::new();
+ let history_path = paths::history_path();
+ if history_path.is_none() {
+ debug!("Could not determine the history path");
+ }
+
+ maybe_load_history(&mut rl, history_path.as_ref().map(|r| r as &Path));
+
loop {
let line = rl.readline("Query> ")?;
rl.add_history_entry(&line);
+ maybe_save_history(&rl, history_path.as_ref().map(|r| r as &Path));
+
let parsed = build_filter(&line);
INTERRUPTED.store(false, Ordering::Relaxed);
match parsed {
@@ -311,6 +324,28 @@ fn repl(opt: &Opt) -> Result<()> {
}
}
+fn maybe_load_history(rl: &mut Editor<()>, path: Option<&Path>) {
+ if let Some(path) = path {
+ debug!("Loading history from {:?}", path);
+ if let Err(e) = rl.load_history(path) {
+ debug!("Loading the history failed: {}", e);
+ }
+ }
+}
+
+fn maybe_save_history(rl: &Editor<()>, path: Option<&Path>) {
+ if let Some(path) = path {
+ debug!("Saving history to {:?}", path);
+ let result: Result<(), Box<dyn std::error::Error>> =
+ fs::create_dir_all(path.parent().unwrap())
+ .map_err(Into::into)
+ .and_then(|_| rl.save_history(path).map_err(Into::into));
+ if let Err(e) = result {
+ debug!("Saving the history failed: {}", e);
+ }
+ }
+}
+
/// Check if the given entry represents a log file, based on the file name.
fn is_log_file(entry: &DirEntry) -> bool {
entry