From a124a480bb9554d8de1d936abbdad869589cd964 Mon Sep 17 00:00:00 2001 From: alemidev Date: Thu, 17 Mar 2022 01:58:22 +0100 Subject: [PATCH] some basic colors --- src/main.rs | 17 +++++++++++------ src/utils.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 41357eb..c024650 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,7 +91,7 @@ fn main() { if re.is_match(memo.body.as_str()) { if many { storage.del(memo.id).unwrap(); - println!("[-] task #{} done", memo.id); + println!("[-] done task : {}", memo.body); } else if found { println!("[!] would remove multiple tasks"); to_remove = None; @@ -104,10 +104,10 @@ fn main() { } if let Some(rm) = to_remove { storage.del(rm.id).unwrap(); - println!("[-] task #{} done", rm.id); + println!("{} done memo: {}", "[-]".bold(), rm.body); } } else { - println!("[!] invalid regex"); + println!("{} invalid regex", format!("[{}]", "!".red()).bold()); } } Some(Commands::Edit { search, body, due }) => { @@ -128,7 +128,11 @@ fn main() { } } storage.set(&m).unwrap(); - println!("[>] updated memo\n{}", m.human()); + println!( + "{} updated memo\n{}", + format!("[{}]", ">".green()).bold().to_string(), + m.colored(), + ); } None => { let all = storage.all(args.old).unwrap(); @@ -140,7 +144,8 @@ fn main() { builder.push_str("[ ] nothing to remember\n"); } for m in all { - builder.push_str(m.human().as_str()); + let tmp = if args.notify { m.human() } else { m.colored() }; + builder.push_str(tmp.as_str()); builder.push('\n'); } if args.notify { @@ -153,7 +158,7 @@ fn main() { n.show().unwrap(); libnotify::uninit(); } else { - println!("{}", "memo-cli".bold()); + println!("{} | {}", "memo-cli".bold(), Local::now().format("%a %d/%m, %H:%M")); print!("{}", builder); } } diff --git a/src/utils.rs b/src/utils.rs index 00c230f..aaa1e11 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,9 +1,11 @@ use crate::storage::Memo; use chrono::{Duration, Utc}; use regex::{Error, Regex}; +use colored::Colorize; pub trait HumanDisplay { fn human(&self) -> String; + fn colored(&self) -> String { return self.human(); } } impl HumanDisplay for Duration { @@ -46,6 +48,32 @@ impl HumanDisplay for Memo { return format!("[*] {}", self.body); } } + + fn colored(&self) -> String { + if self.due.is_some() { + let delta = self.due.unwrap() - Utc::now(); + if delta.le(&Duration::seconds(0)) { + return format!( + "{} {} (+{})", + format!("[{}]", "x".red()).bold(), + self.body.italic(), + delta.human() + ); + } else { + return format!( + "{} {} (-{})", + format!( + "[{}]", + if delta.ge(&Duration::hours(12)) { "o".blue() } else { "o".magenta() } + ).bold(), + self.body.italic(), + delta.human() + ); + } + } else { + return format!("{} {}", format!("[{}]", "*".bright_black()).bold(), self.body); + } + } } pub fn parse_human_duration(input: &str) -> Result {