Something went wrong. Try again.
forked from evanpurkhiser/things3-cloud
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657use std::{io::Write, sync::Arc};
use anyhow::Result;use clap::Args;use iocraft::prelude::*;
use crate::{ app::Cli, commands::{Command, DetailedArgs, detailed_json_conflict, write_json}, ui::{ render_element_to_string, views::{anytime::AnytimeView, json::common::build_tasks_json}, },};
#[derive(Args)]#[command(about = "Show the Anytime view")]pub struct AnytimeArgs { #[command(flatten)] pub detailed: DetailedArgs,}
impl Command for AnytimeArgs { fn run_with_ctx( &self, cli: &Cli, out: &mut dyn Write, ctx: &mut dyn crate::cmd_ctx::CmdCtx, ) -> Result<()> { let store = Arc::new(cli.load_store()?); let today = ctx.today(); let tasks = store.anytime(&today);
let json = cli.json; if json { detailed_json_conflict(json, self.detailed.detailed)?; write_json(out, &build_tasks_json(&tasks, &store, &today))?; return Ok(()); }
let mut ui = element! { ContextProvider(value: Context::owned(store.clone())) { ContextProvider(value: Context::owned(today)) { AnytimeView( items: &tasks, detailed: self.detailed.detailed, ) } } };
let rendered = render_element_to_string(&mut ui, cli.no_color()); writeln!(out, "{}", rendered)?; Ok(()) }}