mod events;
mod filter;
mod render;
mod state;
use crate::history::HistoryStore;
use reedline::HistoryItem;
use state::HistoryBrowser;
use std::io;
const MAX_ENTRIES: i64 = 10000;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HistoryDbMode {
R,
Shell,
}
impl HistoryDbMode {
pub fn display_name(&self) -> &'static str {
match self {
HistoryDbMode::R => "R",
HistoryDbMode::Shell => "Shell",
}
}
}
#[derive(Debug, Clone)]
#[allow(dead_code)] pub enum HistoryBrowserResult {
Cancelled,
Copied(String),
}
fn load_history(store: &HistoryStore) -> io::Result<Vec<HistoryItem>> {
let mut query = reedline::SearchQuery::everything(reedline::SearchDirection::Backward, None);
query.limit = Some(MAX_ENTRIES);
store.search(query).map_err(io::Error::other)
}
pub fn run_history_browser(
store: &HistoryStore,
mode: HistoryDbMode,
) -> io::Result<HistoryBrowserResult> {
let entries = load_history(store)?;
if entries.is_empty() {
println!("# No history entries found.");
return Ok(HistoryBrowserResult::Cancelled);
}
let mut browser = HistoryBrowser::new(entries, mode, store.clone());
browser.run()
}
#[cfg(test)]
mod tests;