diff options
| author | Conrad Ludgate <conradludgate@gmail.com> | 2023-03-26 15:47:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-26 15:47:38 +0100 |
| commit | bb7f00dbef3bf4c7c00c1969cb0089de51bd9ba9 (patch) | |
| tree | 6ac9722a353f844c2896335d2617eb49a677b20f /src/command/client/search/engines.rs | |
| parent | Update README.md (diff) | |
| download | atuin-bb7f00dbef3bf4c7c00c1969cb0089de51bd9ba9.zip | |
chore: use fork of skim (#803)
* use fuzzy-matcher instead of skim
switch to a search-engine abstraction
* fmt
* fix deprecated warnings
Diffstat (limited to 'src/command/client/search/engines.rs')
| -rw-r--r-- | src/command/client/search/engines.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/command/client/search/engines.rs b/src/command/client/search/engines.rs new file mode 100644 index 00000000..878b1431 --- /dev/null +++ b/src/command/client/search/engines.rs @@ -0,0 +1,46 @@ +use async_trait::async_trait; +use atuin_client::{ + database::{Context, Database}, + history::History, + settings::{FilterMode, SearchMode}, +}; +use eyre::Result; + +use super::cursor::Cursor; + +pub mod db; +pub mod skim; + +pub fn engine(search_mode: SearchMode) -> Box<dyn SearchEngine> { + match search_mode { + SearchMode::Skim => Box::new(skim::Search::new()) as Box<_>, + mode => Box::new(db::Search(mode)) as Box<_>, + } +} + +pub struct SearchState { + pub input: Cursor, + pub filter_mode: FilterMode, + pub context: Context, +} + +#[async_trait] +pub trait SearchEngine: Send + Sync + 'static { + async fn full_query( + &mut self, + state: &SearchState, + db: &mut dyn Database, + ) -> Result<Vec<History>>; + + async fn query(&mut self, state: &SearchState, db: &mut dyn Database) -> Result<Vec<History>> { + if state.input.as_str().is_empty() { + Ok(db + .list(state.filter_mode, &state.context, Some(200), true) + .await? + .into_iter() + .collect::<Vec<_>>()) + } else { + self.full_query(state, db).await + } + } +} |
