things3_cloud/commands/
inbox.rs1use crate::app::Cli;
2use crate::commands::{Command, DetailedArgs};
3use crate::common::{colored, fmt_task_line, fmt_task_with_note, BLUE, BOLD, DIM, ICONS};
4use anyhow::Result;
5use clap::Args;
6
7#[derive(Debug, Default, Args)]
8pub struct InboxArgs {
9 #[command(flatten)]
10 pub detailed: DetailedArgs,
11}
12
13impl Command for InboxArgs {
14 fn run_with_ctx(
15 &self,
16 cli: &Cli,
17 out: &mut dyn std::io::Write,
18 ctx: &mut dyn crate::cmd_ctx::CmdCtx,
19 ) -> Result<()> {
20 let store = cli.load_store()?;
21 let today = ctx.today();
22 let tasks = store.inbox();
23
24 if tasks.is_empty() {
25 writeln!(out, "{}", colored("Inbox is empty.", &[DIM], cli.no_color))?;
26 return Ok(());
27 }
28
29 writeln!(
30 out,
31 "{}",
32 colored(
33 &format!("{} Inbox ({} tasks)", ICONS.inbox, tasks.len()),
34 &[BOLD, BLUE],
35 cli.no_color,
36 )
37 )?;
38 writeln!(out)?;
39
40 let id_prefix_len =
41 store.unique_prefix_length(&tasks.iter().map(|t| t.uuid.clone()).collect::<Vec<_>>());
42 for task in tasks {
43 let line = fmt_task_line(
44 &task,
45 &store,
46 false,
47 true,
48 false,
49 Some(id_prefix_len),
50 &today,
51 cli.no_color,
52 );
53 writeln!(
54 out,
55 "{}",
56 fmt_task_with_note(
57 line,
58 &task,
59 " ",
60 Some(id_prefix_len),
61 self.detailed.detailed,
62 cli.no_color,
63 )
64 )?;
65 }
66 Ok(())
67 }
68}