mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
Jump to task
This commit is contained in:
parent
e98c7d4d81
commit
e7c4bc4f9d
3 changed files with 54 additions and 1 deletions
|
@ -59,6 +59,8 @@ Keybindings for task report:
|
||||||
|
|
||||||
1-9: {string} - Run user defined shortcuts
|
1-9: {string} - Run user defined shortcuts
|
||||||
|
|
||||||
|
:: {task id} - Jump to task id
|
||||||
|
|
||||||
c: context switcher menu - Open context switcher menu
|
c: context switcher menu - Open context switcher menu
|
||||||
|
|
||||||
?: help - Help menu
|
?: help - Help menu
|
||||||
|
|
|
@ -119,6 +119,9 @@ Ctrl-y
|
||||||
`1-9`
|
`1-9`
|
||||||
: {string} - Run user defined shortcuts
|
: {string} - Run user defined shortcuts
|
||||||
|
|
||||||
|
`:`
|
||||||
|
: {task id} - Jump to task id
|
||||||
|
|
||||||
`c`
|
`c`
|
||||||
: context switcher menu - Open context switcher menu
|
: context switcher menu - Open context switcher menu
|
||||||
|
|
||||||
|
|
50
src/app.rs
50
src/app.rs
|
@ -34,7 +34,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
||||||
use chrono::{Datelike, Local, NaiveDate, NaiveDateTime, TimeZone, Timelike};
|
use chrono::{Datelike, Local, NaiveDate, NaiveDateTime, TimeZone, Timelike};
|
||||||
|
|
||||||
use anyhow::Context as AnyhowContext;
|
use anyhow::Context as AnyhowContext;
|
||||||
use anyhow::Result;
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use async_std::stream::StreamExt;
|
use async_std::stream::StreamExt;
|
||||||
|
@ -159,6 +159,7 @@ pub enum AppMode {
|
||||||
TaskHelpPopup,
|
TaskHelpPopup,
|
||||||
TaskError,
|
TaskError,
|
||||||
TaskContextMenu,
|
TaskContextMenu,
|
||||||
|
TaskJump,
|
||||||
Calendar,
|
Calendar,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +299,7 @@ impl TaskwarriorTuiApp {
|
||||||
self.terminal_height = rect.height;
|
self.terminal_height = rect.height;
|
||||||
match self.mode {
|
match self.mode {
|
||||||
AppMode::TaskReport
|
AppMode::TaskReport
|
||||||
|
| AppMode::TaskJump
|
||||||
| AppMode::TaskFilter
|
| AppMode::TaskFilter
|
||||||
| AppMode::TaskAdd
|
| AppMode::TaskAdd
|
||||||
| AppMode::TaskAnnotate
|
| AppMode::TaskAnnotate
|
||||||
|
@ -419,6 +421,17 @@ impl TaskwarriorTuiApp {
|
||||||
self.get_position(&self.filter),
|
self.get_position(&self.filter),
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
|
AppMode::TaskJump => {
|
||||||
|
let position = self.get_position(&self.command);
|
||||||
|
self.draw_command(
|
||||||
|
f,
|
||||||
|
rects[1],
|
||||||
|
self.command.as_str(),
|
||||||
|
Span::styled("Jump to Task", Style::default().add_modifier(Modifier::BOLD)),
|
||||||
|
position,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
AppMode::TaskFilter => {
|
AppMode::TaskFilter => {
|
||||||
let position = self.get_position(&self.filter);
|
let position = self.get_position(&self.filter);
|
||||||
if self.show_completion_pane {
|
if self.show_completion_pane {
|
||||||
|
@ -1205,6 +1218,20 @@ impl TaskwarriorTuiApp {
|
||||||
self.current_selection = i;
|
self.current_selection = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn task_report_jump(&mut self) -> Result<()> {
|
||||||
|
if self.tasks.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let i = self.command.as_str().parse::<usize>()?;
|
||||||
|
if let Some(task) = self.task_by_id(i as u64) {
|
||||||
|
let i = self.task_index_by_uuid(*task.uuid()).unwrap();
|
||||||
|
self.current_selection = i;
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("Cannot locate task id {} in report", i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn export_contexts(&mut self) -> Result<()> {
|
pub fn export_contexts(&mut self) -> Result<()> {
|
||||||
let output = Command::new("task").arg("context").output()?;
|
let output = Command::new("task").arg("context").output()?;
|
||||||
let data = String::from_utf8_lossy(&output.stdout);
|
let data = String::from_utf8_lossy(&output.stdout);
|
||||||
|
@ -1989,6 +2016,8 @@ impl TaskwarriorTuiApp {
|
||||||
} else if input == self.keyconfig.filter {
|
} else if input == self.keyconfig.filter {
|
||||||
self.mode = AppMode::TaskFilter;
|
self.mode = AppMode::TaskFilter;
|
||||||
self.update_completion_list();
|
self.update_completion_list();
|
||||||
|
} else if input == Key::Char(':') {
|
||||||
|
self.mode = AppMode::TaskJump;
|
||||||
} else if input == self.keyconfig.shortcut1 {
|
} else if input == self.keyconfig.shortcut1 {
|
||||||
match self.task_shortcut(1) {
|
match self.task_shortcut(1) {
|
||||||
Ok(_) => self.update(true)?,
|
Ok(_) => self.update(true)?,
|
||||||
|
@ -2284,6 +2313,25 @@ impl TaskwarriorTuiApp {
|
||||||
}
|
}
|
||||||
_ => handle_movement(&mut self.command, input),
|
_ => handle_movement(&mut self.command, input),
|
||||||
},
|
},
|
||||||
|
AppMode::TaskJump => match input {
|
||||||
|
Key::Char('\n') => match self.task_report_jump() {
|
||||||
|
Ok(_) => {
|
||||||
|
self.mode = AppMode::TaskReport;
|
||||||
|
self.command.update("", 0);
|
||||||
|
self.update(true)?;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
self.command.update("", 0);
|
||||||
|
self.mode = AppMode::TaskError;
|
||||||
|
self.error = e.to_string();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Key::Esc => {
|
||||||
|
self.command.update("", 0);
|
||||||
|
self.mode = AppMode::TaskReport;
|
||||||
|
}
|
||||||
|
_ => handle_movement(&mut self.command, input),
|
||||||
|
},
|
||||||
AppMode::TaskAdd => match input {
|
AppMode::TaskAdd => match input {
|
||||||
Key::Esc => {
|
Key::Esc => {
|
||||||
if self.show_completion_pane {
|
if self.show_completion_pane {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue