diff --git a/Cargo.lock b/Cargo.lock index c91c082..d28a563 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,9 +83,16 @@ name = "i3status-custom-pim" version = "0.1.0" dependencies = [ "chrono", + "json", "structopt", ] +[[package]] +name = "json" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" + [[package]] name = "lazy_static" version = "1.4.0" diff --git a/Cargo.toml b/Cargo.toml index 9e487e3..a5c31c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ edition = "2018" [dependencies] structopt = "0.3" chrono = "0.4" +json = "0.12.4" diff --git a/src/main.rs b/src/main.rs index 94d40ef..a784d98 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,6 +143,48 @@ fn main() { args.icon, state, count ); } else if args.todo { - println!("todo output"); + let cmd = Command::new("todo") + .arg("--porcelain") + .output(); + + let stdout = match cmd { + Ok(o) => o.stdout, + Err(e) => { + eprintln!("Error running todo: {}", e); + process::exit(1); + } + }; + + let output = match String::from_utf8(stdout) { + Ok(o) => o, + Err(e) => { + eprintln!("Converting output failed: {}", e); + process::exit(1); + } + }; + + let mut parsed = match json::parse(&output){ + Ok(p) => p, + Err(e) => { + eprintln!("parsing JSON failed: {}", e); + process::exit(1); + } + }; + + let count = parsed.len(); + println!("{:#?}", count); + + let mut tasks: Vec = Vec::new(); + for due in parsed.members() { + tasks.push(due.as_str().unwrap().to_string()); + } + /* + for i in parsed { + i.foo(); + } + */ + + + } }