mirror of
https://git.alemi.dev/memo-cli.git
synced 2024-11-22 07:04:50 +01:00
some basic colors
This commit is contained in:
parent
821c1579e5
commit
a124a480bb
2 changed files with 39 additions and 6 deletions
17
src/main.rs
17
src/main.rs
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
src/utils.rs
28
src/utils.rs
|
@ -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> {
|
||||||
|
|
Loading…
Reference in a new issue