mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-24 14:36:42 +02:00
feat: Make auto insert double quotes configurable
This commit is contained in:
parent
2275f75373
commit
5dc40a67d7
3 changed files with 90 additions and 16 deletions
|
@ -30,6 +30,9 @@ uda.taskwarrior-tui.style.report.scrollbar=black
|
|||
uda.taskwarrior-tui.style.report.scrollbar=black
|
||||
uda.taskwarrior-tui.scrollbar.indicator=█
|
||||
uda.taskwarrior-tui.task-report.next.filter=$(task show report.next.filter)
|
||||
uda.taskwarrior-tui.task-report.auto-insert-double-quotes-on-add=true
|
||||
uda.taskwarrior-tui.task-report.auto-insert-double-quotes-on-annotate=true
|
||||
uda.taskwarrior-tui.task-report.auto-insert-double-quotes-on-log=true
|
||||
```
|
||||
|
||||
The `uda.taskwarrior-tui.task-report.next.filter` variable defines the default view at program startup. Set this to any preconfigured report (`task reports`), or create your own report in taskwarrior and specify its name here.
|
||||
|
|
70
src/app.rs
70
src/app.rs
|
@ -285,11 +285,14 @@ impl TaskwarriorTui {
|
|||
app.filter_history.load()?;
|
||||
app.filter_history.add(app.filter.as_str());
|
||||
app.command_history.load()?;
|
||||
app.command.update(r#""""#, 1);
|
||||
app.task_background();
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
pub fn reset_command(&mut self) {
|
||||
self.command.update("", 0)
|
||||
}
|
||||
|
||||
pub fn get_context(&mut self) -> Result<()> {
|
||||
let output = Command::new("task").arg("_get").arg("rc.context").output()?;
|
||||
self.current_context = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
|
@ -533,7 +536,7 @@ impl TaskwarriorTui {
|
|||
);
|
||||
}
|
||||
Mode::Tasks(Action::Jump) => {
|
||||
let position = Self::get_position(&self.command);
|
||||
let (position, cmd) = (0, "");
|
||||
Self::draw_command(
|
||||
f,
|
||||
rects[1],
|
||||
|
@ -569,6 +572,9 @@ impl TaskwarriorTui {
|
|||
);
|
||||
}
|
||||
Mode::Tasks(Action::Log) => {
|
||||
if self.config.uda_auto_insert_double_quotes_on_log && self.command.is_empty() {
|
||||
self.command.update(r#""""#, 1);
|
||||
};
|
||||
let position = Self::get_position(&self.command);
|
||||
if self.show_completion_pane {
|
||||
self.draw_completion_pop_up(f, rects[1], position);
|
||||
|
@ -590,11 +596,11 @@ impl TaskwarriorTui {
|
|||
);
|
||||
}
|
||||
Mode::Tasks(Action::Subprocess) => {
|
||||
let position = Self::get_position(&self.command);
|
||||
let (position, cmd) = (0, "");
|
||||
Self::draw_command(
|
||||
f,
|
||||
rects[1],
|
||||
self.command.as_str(),
|
||||
cmd,
|
||||
(
|
||||
Span::styled("Shell Command", Style::default().add_modifier(Modifier::BOLD)),
|
||||
None,
|
||||
|
@ -631,6 +637,9 @@ impl TaskwarriorTui {
|
|||
);
|
||||
}
|
||||
Mode::Tasks(Action::Annotate) => {
|
||||
if self.config.uda_auto_insert_double_quotes_on_annotate && self.command.is_empty() {
|
||||
self.command.update(r#""""#, 1);
|
||||
};
|
||||
let position = Self::get_position(&self.command);
|
||||
if self.show_completion_pane {
|
||||
self.draw_completion_pop_up(f, rects[1], position);
|
||||
|
@ -657,6 +666,9 @@ impl TaskwarriorTui {
|
|||
);
|
||||
}
|
||||
Mode::Tasks(Action::Add) => {
|
||||
if self.config.uda_auto_insert_double_quotes_on_add && self.command.is_empty() {
|
||||
self.command.update(r#""""#, 1);
|
||||
};
|
||||
let position = Self::get_position(&self.command);
|
||||
if self.show_completion_pane {
|
||||
self.draw_completion_pop_up(f, rects[1], position);
|
||||
|
@ -2824,7 +2836,7 @@ impl TaskwarriorTui {
|
|||
match self.task_subprocess() {
|
||||
Ok(_) => {
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.update(true)?;
|
||||
}
|
||||
Err(e) => {
|
||||
|
@ -2834,7 +2846,7 @@ impl TaskwarriorTui {
|
|||
}
|
||||
}
|
||||
Key::Esc => {
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
}
|
||||
_ => handle_movement(&mut self.command, input),
|
||||
|
@ -2845,7 +2857,7 @@ impl TaskwarriorTui {
|
|||
self.show_completion_pane = false;
|
||||
self.completion_list.unselect();
|
||||
} else {
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.history_status = None;
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
}
|
||||
|
@ -2867,7 +2879,7 @@ impl TaskwarriorTui {
|
|||
Ok(_) => {
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
self.command_history.add(self.command.as_str());
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.history_status = None;
|
||||
self.update(true)?;
|
||||
}
|
||||
|
@ -2944,7 +2956,7 @@ impl TaskwarriorTui {
|
|||
self.show_completion_pane = false;
|
||||
self.completion_list.unselect();
|
||||
} else {
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
self.history_status = None;
|
||||
}
|
||||
|
@ -2966,7 +2978,7 @@ impl TaskwarriorTui {
|
|||
Ok(_) => {
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
self.command_history.add(self.command.as_str());
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.history_status = None;
|
||||
self.update(true)?;
|
||||
}
|
||||
|
@ -3046,18 +3058,18 @@ impl TaskwarriorTui {
|
|||
match self.task_report_jump() {
|
||||
Ok(_) => {
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.update(true)?;
|
||||
}
|
||||
Err(e) => {
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.error = Some(e.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Key::Esc => {
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
}
|
||||
_ => handle_movement(&mut self.command, input),
|
||||
|
@ -3068,7 +3080,7 @@ impl TaskwarriorTui {
|
|||
self.show_completion_pane = false;
|
||||
self.completion_list.unselect();
|
||||
} else {
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.history_status = None;
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
}
|
||||
|
@ -3090,7 +3102,7 @@ impl TaskwarriorTui {
|
|||
Ok(_) => {
|
||||
self.mode = Mode::Tasks(Action::Report);
|
||||
self.command_history.add(self.command.as_str());
|
||||
self.command.update(r#""""#, 1);
|
||||
self.reset_command();
|
||||
self.history_status = None;
|
||||
self.update(true)?;
|
||||
}
|
||||
|
@ -3585,14 +3597,30 @@ mod tests {
|
|||
// setup();
|
||||
app.mode = Mode::Tasks(Action::Add);
|
||||
app.update_completion_list();
|
||||
let input = "\"Wash car\" +test";
|
||||
let input = "Wash car";
|
||||
for c in input.chars() {
|
||||
app.handle_input(Key::Char(c)).unwrap();
|
||||
}
|
||||
app.handle_input(Key::Right).unwrap();
|
||||
let input = " +test";
|
||||
for c in input.chars() {
|
||||
app.handle_input(Key::Char(c)).unwrap();
|
||||
}
|
||||
app.handle_input(Key::Char('\n')).unwrap();
|
||||
|
||||
app.mode = Mode::Tasks(Action::Add);
|
||||
|
||||
app.update_completion_list();
|
||||
|
||||
let backend = TestBackend::new(50, 15);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
.draw(|f| {
|
||||
app.draw(f);
|
||||
app.draw(f);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let input = "Buy groceries";
|
||||
for c in input.chars() {
|
||||
app.handle_input(Key::Char(c)).unwrap();
|
||||
|
@ -3611,6 +3639,16 @@ mod tests {
|
|||
|
||||
app.mode = Mode::Tasks(Action::Add);
|
||||
app.update_completion_list();
|
||||
|
||||
let backend = TestBackend::new(50, 15);
|
||||
let mut terminal = Terminal::new(backend).unwrap();
|
||||
terminal
|
||||
.draw(|f| {
|
||||
app.draw(f);
|
||||
app.draw(f);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let input = "Buy groceries";
|
||||
for c in input.chars() {
|
||||
app.handle_input(Key::Char(c)).unwrap();
|
||||
|
|
|
@ -48,6 +48,9 @@ pub struct Config {
|
|||
pub rule_precedence_color: Vec<String>,
|
||||
pub uda_priority_values: Vec<String>,
|
||||
pub uda_tick_rate: u64,
|
||||
pub uda_auto_insert_double_quotes_on_add: bool,
|
||||
pub uda_auto_insert_double_quotes_on_annotate: bool,
|
||||
pub uda_auto_insert_double_quotes_on_log: bool,
|
||||
pub uda_prefill_task_metadata: bool,
|
||||
pub uda_task_detail_prefetch: usize,
|
||||
pub uda_task_report_show_info: bool,
|
||||
|
@ -93,6 +96,9 @@ impl Config {
|
|||
let rule_precedence_color = Self::get_rule_precedence_color(data);
|
||||
let uda_priority_values = Self::get_uda_priority_values(data);
|
||||
let uda_tick_rate = Self::get_uda_tick_rate(data);
|
||||
let uda_auto_insert_double_quotes_on_add = Self::get_uda_auto_insert_double_quotes_on_add(data);
|
||||
let uda_auto_insert_double_quotes_on_annotate = Self::get_uda_auto_insert_double_quotes_on_annotate(data);
|
||||
let uda_auto_insert_double_quotes_on_log = Self::get_uda_auto_insert_double_quotes_on_log(data);
|
||||
let uda_prefill_task_metadata = Self::get_uda_prefill_task_metadata(data);
|
||||
let uda_task_detail_prefetch = Self::get_uda_task_detail_prefetch(data);
|
||||
let uda_task_report_show_info = Self::get_uda_task_report_show_info(data);
|
||||
|
@ -141,6 +147,9 @@ impl Config {
|
|||
rule_precedence_color,
|
||||
uda_priority_values,
|
||||
uda_tick_rate,
|
||||
uda_auto_insert_double_quotes_on_add,
|
||||
uda_auto_insert_double_quotes_on_annotate,
|
||||
uda_auto_insert_double_quotes_on_log,
|
||||
uda_prefill_task_metadata,
|
||||
uda_task_detail_prefetch,
|
||||
uda_task_report_show_info,
|
||||
|
@ -435,6 +444,30 @@ impl Config {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
fn get_uda_auto_insert_double_quotes_on_add(data: &str) -> bool {
|
||||
Self::get_config("uda.taskwarrior-tui.task-report.auto-insert-double-quotes-on-add", data)
|
||||
.unwrap_or_default()
|
||||
.get_bool()
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
fn get_uda_auto_insert_double_quotes_on_annotate(data: &str) -> bool {
|
||||
Self::get_config(
|
||||
"uda.taskwarrior-tui.task-report.auto-insert-double-quotes-on-annotate",
|
||||
data,
|
||||
)
|
||||
.unwrap_or_default()
|
||||
.get_bool()
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
fn get_uda_auto_insert_double_quotes_on_log(data: &str) -> bool {
|
||||
Self::get_config("uda.taskwarrior-tui.task-report.auto-insert-double-quotes-on-log", data)
|
||||
.unwrap_or_default()
|
||||
.get_bool()
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
fn get_uda_prefill_task_metadata(data: &str) -> bool {
|
||||
Self::get_config("uda.taskwarrior-tui.task-report.pre-fill-task-meta-data", data)
|
||||
.unwrap_or_default()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue