some basic colors

This commit is contained in:
əlemi 2022-03-17 01:58:22 +01:00
parent 821c1579e5
commit a124a480bb
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 39 additions and 6 deletions

View file

@ -91,7 +91,7 @@ fn main() {
if re.is_match(memo.body.as_str()) { if re.is_match(memo.body.as_str()) {
if many { if many {
storage.del(memo.id).unwrap(); storage.del(memo.id).unwrap();
println!("[-] task #{} done", memo.id); println!("[-] done task : {}", memo.body);
} else if found { } else if found {
println!("[!] would remove multiple tasks"); println!("[!] would remove multiple tasks");
to_remove = None; to_remove = None;
@ -104,10 +104,10 @@ fn main() {
} }
if let Some(rm) = to_remove { if let Some(rm) = to_remove {
storage.del(rm.id).unwrap(); storage.del(rm.id).unwrap();
println!("[-] task #{} done", rm.id); println!("{} done memo: {}", "[-]".bold(), rm.body);
} }
} else { } else {
println!("[!] invalid regex"); println!("{} invalid regex", format!("[{}]", "!".red()).bold());
} }
} }
Some(Commands::Edit { search, body, due }) => { Some(Commands::Edit { search, body, due }) => {
@ -128,7 +128,11 @@ fn main() {
} }
} }
storage.set(&m).unwrap(); storage.set(&m).unwrap();
println!("[>] updated memo\n{}", m.human()); println!(
"{} updated memo\n{}",
format!("[{}]", ">".green()).bold().to_string(),
m.colored(),
);
} }
None => { None => {
let all = storage.all(args.old).unwrap(); let all = storage.all(args.old).unwrap();
@ -140,7 +144,8 @@ fn main() {
builder.push_str("[ ] nothing to remember\n"); builder.push_str("[ ] nothing to remember\n");
} }
for m in all { 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'); builder.push('\n');
} }
if args.notify { if args.notify {
@ -153,7 +158,7 @@ fn main() {
n.show().unwrap(); n.show().unwrap();
libnotify::uninit(); libnotify::uninit();
} else { } else {
println!("{}", "memo-cli".bold()); println!("{} | {}", "memo-cli".bold(), Local::now().format("%a %d/%m, %H:%M"));
print!("{}", builder); print!("{}", builder);
} }
} }

View file

@ -1,9 +1,11 @@
use crate::storage::Memo; use crate::storage::Memo;
use chrono::{Duration, Utc}; use chrono::{Duration, Utc};
use regex::{Error, Regex}; use regex::{Error, Regex};
use colored::Colorize;
pub trait HumanDisplay { pub trait HumanDisplay {
fn human(&self) -> String; fn human(&self) -> String;
fn colored(&self) -> String { return self.human(); }
} }
impl HumanDisplay for Duration { impl HumanDisplay for Duration {
@ -46,6 +48,32 @@ impl HumanDisplay for Memo {
return format!("[*] {}", self.body); 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<Duration, Error> { pub fn parse_human_duration(input: &str) -> Result<Duration, Error> {