Skip to content

Commit

Permalink
Merge pull request #15 from jfding/collect-cmd-enhance
Browse files Browse the repository at this point in the history
Collect cmd enhance by adding --inbox arg to specify the from box
  • Loading branch information
jfding authored Sep 16, 2024
2 parents 0f9b305 + b440b22 commit 97d5a97
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <which>) to "today"
Collect {
#[arg(short, long)]
inbox: Option<String>,
},

/// -> postpone all uncompeleted of today to INBOX
Postp,
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() {
println!(" {} left!", "nothing".yellow());
} else {
for t in tasks {
println!("{} {}", "󰄗".to_string().red(), t)
println!("{} {}", "󰄗".red(), t)
}
}

Expand Down Expand Up @@ -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) => {
Expand Down
24 changes: 17 additions & 7 deletions src/taskbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -266,12 +266,22 @@ impl TaskBox {
}

// INBOX -> today
pub fn collect(inbox_path: PathBuf) {
pub fn collect(inbox_path: PathBuf, inbox_from: Option<String>) {
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 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
Expand All @@ -298,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);
Expand All @@ -325,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())
Expand Down

0 comments on commit 97d5a97

Please sign in to comment.