summaryrefslogtreecommitdiff
path: root/src/list.rs
diff options
context:
space:
mode:
authorMo <76752051+mo8it@users.noreply.github.com>2024-09-04 00:40:22 +0200
committerGitHub <noreply@github.com>2024-09-04 00:40:22 +0200
commit20616ff954f19551b7a421193ed915fa9a518915 (patch)
tree9b7546034a6a6032ff20b3027f5b6db1e0c4fd3e /src/list.rs
parentf696d9827023af13489015db8b9f3ab4fce6fee5 (diff)
parentf463cf86627411696922bd703e8c875eec7b367b (diff)
Merge pull request #2098 from frroossst/main
Made the list of exercises searchable, ref #2093
Diffstat (limited to 'src/list.rs')
-rw-r--r--src/list.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/list.rs b/src/list.rs
index 481fb2f..5d7c8dd 100644
--- a/src/list.rs
+++ b/src/list.rs
@@ -21,6 +21,7 @@ mod state;
fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()> {
let mut list_state = ListState::new(app_state, stdout)?;
+ let mut is_searching = false;
loop {
match event::read().context("Failed to read terminal event")? {
@@ -32,6 +33,29 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
list_state.message.clear();
+ let curr_key = key.code;
+
+ if is_searching {
+ match curr_key {
+ KeyCode::Esc | KeyCode::Enter => {
+ is_searching = false;
+ list_state.search_query.clear();
+ }
+ KeyCode::Char(k) => {
+ list_state.search_query.push(k);
+ list_state.apply_search_query();
+ list_state.draw(stdout)?;
+ }
+ KeyCode::Backspace => {
+ list_state.search_query.pop();
+ list_state.apply_search_query();
+ list_state.draw(stdout)?;
+ }
+ _ => {}
+ }
+ continue;
+ }
+
match key.code {
KeyCode::Char('q') => return Ok(()),
KeyCode::Down | KeyCode::Char('j') => list_state.select_next(),
@@ -66,6 +90,10 @@ fn handle_list(app_state: &mut AppState, stdout: &mut StdoutLock) -> Result<()>
return Ok(());
}
}
+ KeyCode::Char('s' | '/') => {
+ list_state.message.push_str("search:|");
+ is_searching = true;
+ }
// Redraw to remove the message.
KeyCode::Esc => (),
_ => continue,