mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
Add delete prompt
This commit is contained in:
parent
516d3d606f
commit
22cccd99a6
1 changed files with 42 additions and 5 deletions
47
src/app.rs
47
src/app.rs
|
@ -162,6 +162,7 @@ pub enum AppMode {
|
||||||
TaskError,
|
TaskError,
|
||||||
TaskContextMenu,
|
TaskContextMenu,
|
||||||
TaskJump,
|
TaskJump,
|
||||||
|
TaskDeletePrompt,
|
||||||
Calendar,
|
Calendar,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,6 +173,7 @@ pub struct TaskwarriorTuiApp {
|
||||||
pub context_table_state: TableState,
|
pub context_table_state: TableState,
|
||||||
pub current_context_filter: String,
|
pub current_context_filter: String,
|
||||||
pub current_context: String,
|
pub current_context: String,
|
||||||
|
pub delete: LineBuffer,
|
||||||
pub command: LineBuffer,
|
pub command: LineBuffer,
|
||||||
pub filter: LineBuffer,
|
pub filter: LineBuffer,
|
||||||
pub modify: LineBuffer,
|
pub modify: LineBuffer,
|
||||||
|
@ -244,6 +246,7 @@ impl TaskwarriorTuiApp {
|
||||||
current_selection_id: None,
|
current_selection_id: None,
|
||||||
current_context_filter: "".to_string(),
|
current_context_filter: "".to_string(),
|
||||||
current_context: "".to_string(),
|
current_context: "".to_string(),
|
||||||
|
delete: LineBuffer::with_capacity(MAX_LINE),
|
||||||
command: LineBuffer::with_capacity(MAX_LINE),
|
command: LineBuffer::with_capacity(MAX_LINE),
|
||||||
filter: LineBuffer::with_capacity(MAX_LINE),
|
filter: LineBuffer::with_capacity(MAX_LINE),
|
||||||
modify: LineBuffer::with_capacity(MAX_LINE),
|
modify: LineBuffer::with_capacity(MAX_LINE),
|
||||||
|
@ -313,6 +316,7 @@ impl TaskwarriorTuiApp {
|
||||||
| AppMode::TaskAdd
|
| AppMode::TaskAdd
|
||||||
| AppMode::TaskAnnotate
|
| AppMode::TaskAnnotate
|
||||||
| AppMode::TaskContextMenu
|
| AppMode::TaskContextMenu
|
||||||
|
| AppMode::TaskDeletePrompt
|
||||||
| AppMode::TaskError
|
| AppMode::TaskError
|
||||||
| AppMode::TaskHelpPopup
|
| AppMode::TaskHelpPopup
|
||||||
| AppMode::TaskSubprocess
|
| AppMode::TaskSubprocess
|
||||||
|
@ -565,6 +569,16 @@ impl TaskwarriorTuiApp {
|
||||||
);
|
);
|
||||||
self.draw_context_menu(f, 80, 50);
|
self.draw_context_menu(f, 80, 50);
|
||||||
}
|
}
|
||||||
|
AppMode::TaskDeletePrompt => {
|
||||||
|
f.set_cursor(rects[1].x + self.delete.pos() as u16 + 1, rects[1].y + 1);
|
||||||
|
f.render_widget(Clear, rects[1]);
|
||||||
|
self.draw_command(
|
||||||
|
f,
|
||||||
|
rects[1],
|
||||||
|
self.delete.as_str(),
|
||||||
|
Span::styled("Delete Task?", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
panic!("Reached unreachable code. Something went wrong");
|
panic!("Reached unreachable code. Something went wrong");
|
||||||
}
|
}
|
||||||
|
@ -2097,11 +2111,17 @@ impl TaskwarriorTuiApp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if input == self.keyconfig.delete {
|
} else if input == self.keyconfig.delete {
|
||||||
match self.task_delete() {
|
self.mode = AppMode::TaskDeletePrompt;
|
||||||
Ok(_) => self.update(true)?,
|
match self.task_current() {
|
||||||
Err(e) => {
|
Some(t) => {
|
||||||
self.mode = AppMode::TaskError;
|
let s = format!(
|
||||||
self.error = e;
|
"Delete task {} - '{}' ? Hit `x` again or `Enter` to confirm. Hit `Esc` to cancel.",
|
||||||
|
t.id().unwrap_or_default(),
|
||||||
|
t.description()
|
||||||
|
);
|
||||||
|
self.delete.update(&s, s.len())
|
||||||
|
},
|
||||||
|
None => self.mode = AppMode::TaskReport,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if input == self.keyconfig.start_stop {
|
} else if input == self.keyconfig.start_stop {
|
||||||
|
@ -2737,6 +2757,23 @@ impl TaskwarriorTuiApp {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
AppMode::TaskDeletePrompt => match input {
|
||||||
|
Key::Char('x') | Key::Char('\n') => match self.task_delete() {
|
||||||
|
Ok(_) => {
|
||||||
|
self.mode = AppMode::TaskReport;
|
||||||
|
self.update()?;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
self.mode = AppMode::TaskError;
|
||||||
|
self.error = e;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Key::Esc => {
|
||||||
|
self.delete.update("", 0);
|
||||||
|
self.mode = AppMode::TaskReport;
|
||||||
|
}
|
||||||
|
_ => handle_movement(&mut self.command, input),
|
||||||
|
},
|
||||||
AppMode::TaskError => self.mode = AppMode::TaskReport,
|
AppMode::TaskError => self.mode = AppMode::TaskReport,
|
||||||
AppMode::Calendar => {
|
AppMode::Calendar => {
|
||||||
if input == self.keyconfig.quit || input == Key::Ctrl('c') {
|
if input == self.keyconfig.quit || input == Key::Ctrl('c') {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue