things3_cloud/commands/
inbox.rs1use std::sync::Arc;
2
3use anyhow::Result;
4use clap::Args;
5use iocraft::prelude::*;
6
7use crate::{
8 app::Cli,
9 commands::{Command, DetailedArgs, detailed_json_conflict, write_json},
10 ui::{
11 render_element_to_string,
12 views::{inbox::InboxView, json::common::build_tasks_json},
13 },
14};
15
16#[derive(Debug, Default, Args)]
17pub struct InboxArgs {
18 #[command(flatten)]
19 pub detailed: DetailedArgs,
20}
21
22impl Command for InboxArgs {
23 fn run_with_ctx(
24 &self,
25 cli: &Cli,
26 out: &mut dyn std::io::Write,
27 ctx: &mut dyn crate::cmd_ctx::CmdCtx,
28 ) -> Result<()> {
29 let store = Arc::new(cli.load_store()?);
30 let today = ctx.today();
31 let tasks = store.inbox();
32
33 let json = cli.json;
34 if json {
35 if detailed_json_conflict(json, self.detailed.detailed) {
36 return Ok(());
37 }
38 write_json(out, &build_tasks_json(&tasks, &store, &today))?;
39 return Ok(());
40 }
41
42 let mut ui = element! {
43 ContextProvider(value: Context::owned(store.clone())) {
44 ContextProvider(value: Context::owned(today)) {
45 InboxView(
46 items: &tasks,
47 detailed: self.detailed.detailed,
48 )
49 }
50 }
51 };
52 let rendered = render_element_to_string(&mut ui, cli.no_color);
53 writeln!(out, "{}", rendered)?;
54 Ok(())
55 }
56}