mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 12:17:19 +02:00
feat: Support taskwarrior v2.6.x context ✨
This commit is contained in:
parent
2738f417a2
commit
dce55ebf89
2 changed files with 36 additions and 12 deletions
44
src/app.rs
44
src/app.rs
|
@ -1215,6 +1215,7 @@ impl TaskwarriorTui {
|
||||||
let contexts = self
|
let contexts = self
|
||||||
.contexts
|
.contexts
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|c| &c.typ == "read")
|
||||||
.map(|c| vec![c.name.clone(), c.description.clone(), c.active.clone()])
|
.map(|c| vec![c.name.clone(), c.description.clone(), c.active.clone()])
|
||||||
.collect();
|
.collect();
|
||||||
let headers = vec!["Name".to_string(), "Description".to_string(), "Active".to_string()];
|
let headers = vec!["Name".to_string(), "Description".to_string(), "Active".to_string()];
|
||||||
|
@ -1245,6 +1246,7 @@ impl TaskwarriorTui {
|
||||||
task::block_on(self.update_task_details())?;
|
task::block_on(self.update_task_details())?;
|
||||||
}
|
}
|
||||||
self.selection_fix();
|
self.selection_fix();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1528,27 +1530,46 @@ impl TaskwarriorTui {
|
||||||
self.contexts = vec![];
|
self.contexts = vec![];
|
||||||
|
|
||||||
for (i, line) in data.trim().split('\n').enumerate() {
|
for (i, line) in data.trim().split('\n').enumerate() {
|
||||||
|
if line.starts_with(" ") && line.trim().starts_with("write") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let line = line.trim();
|
let line = line.trim();
|
||||||
if line.is_empty() || line == "Use 'task context none' to unset the current context." {
|
if line.is_empty() || line == "Use 'task context none' to unset the current context." {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mut s = line.split(' ');
|
|
||||||
let name = s.next().unwrap_or_default();
|
|
||||||
let active = s.last().unwrap_or_default();
|
|
||||||
let definition = line.replacen(name, "", 1);
|
|
||||||
let definition = definition.strip_suffix(active).unwrap_or_default();
|
|
||||||
if i == 0 || i == 1 {
|
if i == 0 || i == 1 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let context = Context::new(name.to_string(), definition.trim().to_string(), active.to_string());
|
let mut s = line.split_whitespace();
|
||||||
|
let name = s.next().unwrap_or_default();
|
||||||
|
let typ = s.next().unwrap_or_default();
|
||||||
|
let active = s.last().unwrap_or_default();
|
||||||
|
let definition = line.replacen(name, "", 1);
|
||||||
|
let definition = definition.replacen(typ, "", 1);
|
||||||
|
let definition = definition.strip_suffix(active).unwrap_or_default();
|
||||||
|
let context = Context::new(
|
||||||
|
name.to_string(),
|
||||||
|
definition.trim().to_string(),
|
||||||
|
active.to_string(),
|
||||||
|
typ.to_string(),
|
||||||
|
);
|
||||||
self.contexts.push(context);
|
self.contexts.push(context);
|
||||||
}
|
}
|
||||||
if self.contexts.iter().any(|r| r.active != "no") {
|
if self.contexts.iter().any(|r| r.active != "no") {
|
||||||
self.contexts
|
self.contexts.insert(
|
||||||
.insert(0, Context::new("none".to_string(), "".to_string(), "no".to_string()));
|
0,
|
||||||
|
Context::new("none".to_string(), "".to_string(), "no".to_string(), "read".to_string()),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
self.contexts
|
self.contexts.insert(
|
||||||
.insert(0, Context::new("none".to_string(), "".to_string(), "yes".to_string()));
|
0,
|
||||||
|
Context::new(
|
||||||
|
"none".to_string(),
|
||||||
|
"".to_string(),
|
||||||
|
"yes".to_string(),
|
||||||
|
"read".to_string(),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -4226,13 +4247,14 @@ mod tests {
|
||||||
test_case(&expected);
|
test_case(&expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[test]
|
||||||
fn test_draw_context_menu() {
|
fn test_draw_context_menu() {
|
||||||
let test_case = |expected: &Buffer| {
|
let test_case = |expected: &Buffer| {
|
||||||
let mut app = TaskwarriorTui::new("next").unwrap();
|
let mut app = TaskwarriorTui::new("next").unwrap();
|
||||||
|
|
||||||
app.mode = Mode::Tasks(Action::ContextMenu);
|
app.mode = Mode::Tasks(Action::ContextMenu);
|
||||||
app.task_report_next();
|
app.task_report_next();
|
||||||
app.context_next();
|
// app.context_next();
|
||||||
app.update(true).unwrap();
|
app.update(true).unwrap();
|
||||||
|
|
||||||
let backend = TestBackend::new(80, 10);
|
let backend = TestBackend::new(80, 10);
|
||||||
|
|
|
@ -13,14 +13,16 @@ pub struct Context {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub active: String,
|
pub active: String,
|
||||||
|
pub typ: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
pub fn new(name: String, description: String, active: String) -> Self {
|
pub fn new(name: String, description: String, active: String, typ: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
active,
|
active,
|
||||||
|
typ,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue