summaryrefslogtreecommitdiff
path: root/src/list.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-08 02:41:48 +0200
committermo8it <mo8it@proton.me>2024-04-08 02:41:48 +0200
commit7c4d33654fb37200905c06c198f427545fedd461 (patch)
treed2e3a5d8e98d26cb59f19646fb84fa3e399ef9d9 /src/list.rs
parent05729b27a06d50d4d3516c1b62a2c7450e4ac12a (diff)
Implement done/pending filters
Diffstat (limited to 'src/list.rs')
-rw-r--r--src/list.rs30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/list.rs b/src/list.rs
index 3d91b8a..d7fa05f 100644
--- a/src/list.rs
+++ b/src/list.rs
@@ -11,7 +11,7 @@ mod state;
use crate::{exercise::Exercise, state_file::StateFile};
-use self::state::UiState;
+use self::state::{Filter, UiState};
pub fn list(state_file: &mut StateFile, exercises: &[Exercise]) -> Result<()> {
let mut stdout = io::stdout().lock();
@@ -50,20 +50,44 @@ pub fn list(state_file: &mut StateFile, exercises: &[Exercise]) -> Result<()> {
KeyCode::Up | KeyCode::Char('k') => ui_state.select_previous(),
KeyCode::Home | KeyCode::Char('g') => ui_state.select_first(),
KeyCode::End | KeyCode::Char('G') => ui_state.select_last(),
+ KeyCode::Char('d') => {
+ let message = if ui_state.filter == Filter::Done {
+ ui_state.filter = Filter::None;
+ "Disabled filter DONE"
+ } else {
+ ui_state.filter = Filter::Done;
+ "Enabled filter DONE │ Press d again to disable the filter"
+ };
+
+ ui_state = ui_state.with_updated_rows(state_file);
+ ui_state.message.push_str(message);
+ }
+ KeyCode::Char('p') => {
+ let message = if ui_state.filter == Filter::Pending {
+ ui_state.filter = Filter::None;
+ "Disabled filter PENDING"
+ } else {
+ ui_state.filter = Filter::Pending;
+ "Enabled filter PENDING │ Press p again to disable the filter"
+ };
+
+ ui_state = ui_state.with_updated_rows(state_file);
+ ui_state.message.push_str(message);
+ }
KeyCode::Char('r') => {
let selected = ui_state.selected();
let exercise = &exercises[selected];
exercise.reset()?;
state_file.reset(selected)?;
- ui_state.table = ui_state.table.rows(UiState::rows(state_file, exercises));
+ ui_state = ui_state.with_updated_rows(state_file);
ui_state
.message
.write_fmt(format_args!("The exercise {exercise} has been reset!"))?;
}
KeyCode::Char('c') => {
state_file.set_next_exercise_ind(ui_state.selected())?;
- ui_state.table = ui_state.table.rows(UiState::rows(state_file, exercises));
+ ui_state = ui_state.with_updated_rows(state_file);
}
_ => (),
}