Vim like search (#279)

* add quick search within a list

* vim like search navigation

* close cmd line with esc

* format

* document changes in README
This commit is contained in:
Moshe Sherman
2020-10-05 14:50:12 +03:00
committed by GitHub
parent fc79889665
commit f2b4f01242
6 changed files with 121 additions and 12 deletions

View File

@@ -42,6 +42,14 @@ impl Default for MoveAmount {
}
}
#[derive(Display, Clone, Serialize, Deserialize, Debug)]
#[strum(serialize_all = "lowercase")]
pub enum JumpMode {
Previous,
Next,
Query(String),
}
#[derive(Display, Clone, Serialize, Deserialize, Debug)]
#[strum(serialize_all = "lowercase")]
pub enum ShiftMode {
@@ -102,6 +110,7 @@ pub enum Command {
Move(MoveMode, MoveAmount),
Shift(ShiftMode, Option<i32>),
Search(String),
Jump(JumpMode),
Help,
ReloadConfig,
Noop,
@@ -157,6 +166,7 @@ impl fmt::Display for Command {
Command::Move(mode, MoveAmount::Integer(amount)) => format!("move {} {}", mode, amount),
Command::Shift(mode, amount) => format!("shift {} {}", mode, amount.unwrap_or(1)),
Command::Search(term) => format!("search {}", term),
Command::Jump(term) => format!("jump {}", term),
Command::Help => "help".to_string(),
Command::ReloadConfig => "reload".to_string(),
};
@@ -224,6 +234,7 @@ pub fn parse(input: &str) -> Option<Command> {
_ => None,
})
.map(Command::Open),
"jump" => Some(Command::Jump(JumpMode::Query(args.join(" ")))),
"search" => args
.get(0)
.map(|query| Command::Search((*query).to_string())),