From c173ea55425b52547b671af5dd595a19cb689ab8 Mon Sep 17 00:00:00 2001 From: JF Ding Date: Mon, 16 Sep 2024 23:22:05 +0800 Subject: [PATCH 1/2] add opt to cmd collect to move in tasks from any box --- src/cli.rs | 7 +++++-- src/main.rs | 4 ++-- src/taskbox.rs | 11 ++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 1cba9a1..6a199c8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -64,8 +64,11 @@ pub enum Commands { /// -> shift all uncompeleted in "today" to "tomorrow" Shift, - /// -> collect all uncompeleted in INBOX to "today" - Collect, + /// -> collect all uncompeleted in INBOX(or --inbox ) to "today" + Collect { + #[arg(short, long)] + inbox: Option, + }, /// -> postpone all uncompeleted of today to INBOX Postp, diff --git a/src/main.rs b/src/main.rs index 4c93226..b9c1779 100644 --- a/src/main.rs +++ b/src/main.rs @@ -137,8 +137,8 @@ fn main() { TaskBox::shift(inbox_path) } - Some(Commands::Collect) => { - TaskBox::collect(inbox_path) + Some(Commands::Collect { inbox }) => { + TaskBox::collect(inbox_path, inbox) } Some(Commands::Postp) => { diff --git a/src/taskbox.rs b/src/taskbox.rs index 28ed97d..dcba437 100644 --- a/src/taskbox.rs +++ b/src/taskbox.rs @@ -266,12 +266,17 @@ impl TaskBox { } // INBOX -> today - pub fn collect(inbox_path: PathBuf) { + pub fn collect(inbox_path: PathBuf, inbox_from: Option) { let basedir = inbox_path.as_path().parent().unwrap(); let mut today_todo = TaskBox::new(basedir.join(get_today()).with_extension("md")); - let mut inbox_todo = TaskBox::new(basedir.join(INBOX_NAME).with_extension("md")); - today_todo._move_in(&mut inbox_todo) + let mut from_todo = if let Some(from_name) = inbox_from { + TaskBox::new(basedir.join(from_name).with_extension("md")) + } else { + TaskBox::new(basedir.join(INBOX_NAME).with_extension("md")) + }; + + today_todo._move_in(&mut from_todo) } // today -> INBOX From b440b222bdf04cf891470f609c449c05df695ca8 Mon Sep 17 00:00:00 2001 From: JF Ding Date: Mon, 16 Sep 2024 23:35:03 +0800 Subject: [PATCH 2/2] check and skip collect tasks from today to today --- src/main.rs | 2 +- src/taskbox.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index b9c1779..fe973ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ fn main() { println!(" {} left!", "nothing".yellow()); } else { for t in tasks { - println!("{} {}", "󰄗".to_string().red(), t) + println!("{} {}", "󰄗".red(), t) } } diff --git a/src/taskbox.rs b/src/taskbox.rs index dcba437..d1fa67c 100644 --- a/src/taskbox.rs +++ b/src/taskbox.rs @@ -150,7 +150,7 @@ impl TaskBox { println!("{}  {} ↩️", from.unwrap().green(), to.unwrap().blue()); for task in tasks { - println!("{} : {}", " 󰄗".to_string().red(), task); + println!("{} : {}", " 󰄗".red(), task); self.tasks.push((task.clone(), false)); } @@ -269,6 +269,11 @@ impl TaskBox { pub fn collect(inbox_path: PathBuf, inbox_from: Option) { let basedir = inbox_path.as_path().parent().unwrap(); + if inbox_from == Some(get_today()) { + println!("{} is not a valid source", "󰄹 today".red()); + return + } + let mut today_todo = TaskBox::new(basedir.join(get_today()).with_extension("md")); let mut from_todo = if let Some(from_name) = inbox_from { TaskBox::new(basedir.join(from_name).with_extension("md")) @@ -303,13 +308,13 @@ impl TaskBox { if line.is_empty() { continue } if let Some(stripped) = line.strip_prefix(PREFIX) { - println!("{} : {}", " 󰄗".to_string().red(), stripped); + println!("{} : {}", " 󰄗".red(), stripped); newt.push((stripped.to_string(), false)) } } if newt.is_empty() { - println!("{} found", "nothing".to_string().yellow()) + println!("{} found", "nothing".yellow()) } else { self._load(); self.tasks.append(&mut newt); @@ -330,7 +335,7 @@ impl TaskBox { } boxes.sort(); boxes.reverse(); boxes.into_iter().for_each( |b| { - print!("{} {}","󰄹".to_string().blue(), b); + print!("{} {}","󰄹".blue(), b); let tbox = TaskBox::new(basedir.join(b).with_extension("md")); if tbox.alias.is_some() { println!(" ({})", tbox.alias.unwrap().bright_black().blink())