From 4e49696dab4fc50d86676d8a0755f85683890d6e Mon Sep 17 00:00:00 2001 From: alemidev Date: Mon, 14 Mar 2022 23:12:41 +0100 Subject: [PATCH] added basic notifications, args cleanup --- Cargo.toml | 1 + src/main.rs | 44 ++++++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6c84243..a999ab2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ edition = "2021" [dependencies] regex = "1" chrono = "0.4.19" +libnotify = "1.0.3" clap = { version = "3.1.6", features = ["derive"] } rusqlite = { version="0.27.0", features=["chrono"] } diff --git a/src/main.rs b/src/main.rs index 6cfdeee..70e67f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ mod storage; mod utils; -use chrono::{DateTime, Utc}; +use chrono::{DateTime, Utc, Local}; use clap::{Parser, Subcommand}; use regex::Regex; pub use storage::{open_sqlite_storage, Memo, MemoStorage}; @@ -9,16 +9,18 @@ use utils::{parse_human_duration, HumanDisplay}; #[derive(Parser)] #[clap(author, version, about, long_about = None)] -#[clap(propagate_version = true, disable_colored_help = true)] +#[clap(disable_colored_help = true)] #[clap(subcommand_required = false)] #[clap(disable_help_subcommand = true)] struct Cli { #[clap(subcommand)] command: Option, - #[clap(short, long, help = "location for database file")] - db_path: Option, + #[clap(short, long, help = "show memos in a notification")] + notify: bool, #[clap(long, help = "show completed tasks")] old: bool, + #[clap(short, long, help = "location for database file")] + db_path: Option, } #[derive(Subcommand)] @@ -30,16 +32,13 @@ enum Commands { #[clap(required = true)] body: Vec, #[clap(short, long, help = "due time relative to now")] - due: Option, + due: Option, // TODO allow to pass date }, Done { search: String, - #[clap(long)] + #[clap(long, help = "delete more than one task if matched")] many: bool, - }, - Del { - id: u32, - }, + } } fn main() { @@ -93,17 +92,30 @@ fn main() { println!("[!] invalid regex"); } } - Some(Commands::Del { id }) => { - storage.del(id).unwrap(); - println!("[-] task #{} deleted", id); - } None => { let all = storage.all(args.old).unwrap(); + let mut builder = String::new(); + if args.old { + builder.push_str("Archived memos:\n"); + } if all.len() < 1 { - println!("[ ] nothing to remember"); + builder.push_str("[ ] nothing to remember\n"); } for m in all { - println!("{}", m.human()); + builder.push_str(m.human().as_str()); + builder.push('\n'); + } + if args.notify { + libnotify::init("memo-cli").unwrap(); + let n = libnotify::Notification::new( + format!("memo-cli | {}", Local::now().format("%a %d/%m, %H:%M")).as_str(), + Some(builder.as_str()), + None + ); + n.show().unwrap(); + libnotify::uninit(); + } else { + print!("{}", builder); } } }