mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
feat: Add task version check ✨
This commit is contained in:
parent
8969992930
commit
561c1fb2a2
3 changed files with 40 additions and 15 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -1412,6 +1412,7 @@ dependencies = [
|
||||||
"unicode-truncate",
|
"unicode-truncate",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
"version-compare",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1524,6 +1525,12 @@ version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version-compare"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
|
|
|
@ -43,6 +43,7 @@ unicode-segmentation = "1.8.0"
|
||||||
unicode-truncate = "0.2.0"
|
unicode-truncate = "0.2.0"
|
||||||
unicode-width = "0.1.8"
|
unicode-width = "0.1.8"
|
||||||
uuid = { version = "0.8.2", features = ["serde", "v4"] }
|
uuid = { version = "0.8.2", features = ["serde", "v4"] }
|
||||||
|
version-compare = "0.1.0"
|
||||||
|
|
||||||
[package.metadata.rpm]
|
[package.metadata.rpm]
|
||||||
package = "taskwarrior-tui"
|
package = "taskwarrior-tui"
|
||||||
|
|
43
src/app.rs
43
src/app.rs
|
@ -78,6 +78,8 @@ use std::borrow::Borrow;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use task_hookrs::project::Project;
|
use task_hookrs::project::Project;
|
||||||
|
|
||||||
|
use version_compare::{Cmp, Version};
|
||||||
|
|
||||||
const MAX_LINE: usize = 4096;
|
const MAX_LINE: usize = 4096;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
@ -203,6 +205,7 @@ pub struct TaskwarriorTui {
|
||||||
pub report: String,
|
pub report: String,
|
||||||
pub projects: ProjectsState,
|
pub projects: ProjectsState,
|
||||||
pub contexts: ContextsState,
|
pub contexts: ContextsState,
|
||||||
|
pub task_version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskwarriorTui {
|
impl TaskwarriorTui {
|
||||||
|
@ -231,6 +234,17 @@ impl TaskwarriorTui {
|
||||||
let c = Config::new(&data, report)?;
|
let c = Config::new(&data, report)?;
|
||||||
let kc = KeyConfig::new(&data)?;
|
let kc = KeyConfig::new(&data)?;
|
||||||
|
|
||||||
|
let output = std::process::Command::new("task")
|
||||||
|
.arg("--version")
|
||||||
|
.output()
|
||||||
|
.context("Unable to run `task --version`")
|
||||||
|
.unwrap();
|
||||||
|
let task_version = String::from_utf8_lossy(&output.stdout).to_string();
|
||||||
|
|
||||||
|
if Version::from(&task_version).is_none() {
|
||||||
|
return Err(anyhow!("Unable to parse `task --version`.\nGot {}", task_version));
|
||||||
|
}
|
||||||
|
|
||||||
let (w, h) = crossterm::terminal::size()?;
|
let (w, h) = crossterm::terminal::size()?;
|
||||||
|
|
||||||
let mut app = Self {
|
let mut app = Self {
|
||||||
|
@ -269,6 +283,7 @@ impl TaskwarriorTui {
|
||||||
report: report.to_string(),
|
report: report.to_string(),
|
||||||
projects: ProjectsState::new(),
|
projects: ProjectsState::new(),
|
||||||
contexts: ContextsState::new(),
|
contexts: ContextsState::new(),
|
||||||
|
task_version,
|
||||||
};
|
};
|
||||||
|
|
||||||
for c in app.config.filter.chars() {
|
for c in app.config.filter.chars() {
|
||||||
|
@ -1571,28 +1586,30 @@ impl TaskwarriorTui {
|
||||||
task.arg("rc.json.array=on");
|
task.arg("rc.json.array=on");
|
||||||
task.arg("rc.confirmation=off");
|
task.arg("rc.confirmation=off");
|
||||||
|
|
||||||
let filter = if self.current_context_filter.is_empty() {
|
if Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap() {
|
||||||
format!("'{}'", self.filter.as_str())
|
task.arg(format!("'{}'", self.filter.as_str().trim()));
|
||||||
} else {
|
} else {
|
||||||
format!("'{}' '{}'", self.filter.as_str(), self.current_context_filter)
|
task.arg(self.filter.as_str().trim());
|
||||||
};
|
}
|
||||||
|
|
||||||
match shlex::split(&filter) {
|
if !self.current_context_filter.is_empty()
|
||||||
Some(cmd) => {
|
&& Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap()
|
||||||
for s in cmd {
|
{
|
||||||
task.arg(&s);
|
task.arg(format!("'{}'", self.current_context_filter.trim()));
|
||||||
}
|
} else if !self.current_context_filter.is_empty() {
|
||||||
}
|
task.arg(format!("'\\({}\\)'", self.current_context_filter));
|
||||||
None => {
|
|
||||||
task.arg("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task.arg("export");
|
task.arg("export");
|
||||||
|
|
||||||
|
if Version::from(&self.task_version).unwrap() >= Version::from("2.6.0").unwrap() {
|
||||||
task.arg(&self.report);
|
task.arg(&self.report);
|
||||||
|
}
|
||||||
|
|
||||||
let output = task.output()?;
|
let output = task.output()?;
|
||||||
let data = String::from_utf8_lossy(&output.stdout);
|
let data = String::from_utf8_lossy(&output.stdout);
|
||||||
let error = String::from_utf8_lossy(&output.stderr);
|
let error = String::from_utf8_lossy(&output.stderr);
|
||||||
|
|
||||||
if !error.contains("The expression could not be evaluated.") {
|
if !error.contains("The expression could not be evaluated.") {
|
||||||
if let Ok(imported) = import(data.as_bytes()) {
|
if let Ok(imported) = import(data.as_bytes()) {
|
||||||
self.tasks = imported;
|
self.tasks = imported;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue