From 378be6b790c3d504c8d7d873ce035daf926e98ed Mon Sep 17 00:00:00 2001 From: Krut Patel Date: Wed, 22 Mar 2023 21:46:59 +0530 Subject: Allow changing search_mode during interactive search (#586) * Make search_mode a part of SearchState * Allow changing search mode using ctrl+s * Tweak state reset for switched_search_mode * Improve search_mode display in interactive mode * Incorporate review suggestion * Tweak language * Fix Clippy and format --- atuin-client/src/settings.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'atuin-client/src') diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs index de9bd640..bbbd78ee 100644 --- a/atuin-client/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -34,6 +34,32 @@ pub enum SearchMode { Skim, } +impl SearchMode { + pub fn as_str(&self) -> &'static str { + match self { + SearchMode::Prefix => "PREFIX", + SearchMode::FullText => "FULLTXT", + SearchMode::Fuzzy => "FUZZY", + SearchMode::Skim => "SKIM", + } + } + pub fn next(&self, settings: &Settings) -> Self { + match self { + SearchMode::Prefix => SearchMode::FullText, + SearchMode::FullText => { + // if the user is using skim, we go to skim, otherwise fuzzy. + if settings.search_mode == SearchMode::Skim { + SearchMode::Skim + } else { + SearchMode::Fuzzy + } + } + SearchMode::Fuzzy => SearchMode::Prefix, + SearchMode::Skim => SearchMode::Prefix, + } + } +} + #[derive(Clone, Debug, Deserialize, Copy, PartialEq, Eq, ValueEnum)] pub enum FilterMode { #[serde(rename = "global")] -- cgit v1.3.1