diff --git a/crates/hyperlog-tui/src/components.rs b/crates/hyperlog-tui/src/components.rs index 3f5767d..1080776 100644 --- a/crates/hyperlog-tui/src/components.rs +++ b/crates/hyperlog-tui/src/components.rs @@ -1,11 +1,11 @@ use std::ops::Deref; use anyhow::Result; -use hyperlog_core::log::GraphItem; +use hyperlog_core::log::{GraphItem, ItemState}; use itertools::Itertools; use ratatui::{prelude::*, widgets::*}; -use crate::{command_parser::Commands, commands::Command, state::SharedState}; +use crate::{command_parser::Commands, state::SharedState}; pub struct GraphExplorer<'a> { state: SharedState, @@ -40,8 +40,7 @@ impl<'a> GraphExplorer<'a> { .state .querier .get( - // FIXME: Replace with a setting or default instead, probaby user - "kjuulh", + &self.inner.root, self.inner .current_path .map(|p| p.split('.').collect::>()) @@ -141,13 +140,15 @@ impl<'a> GraphExplorer<'a> { } } - pub fn execute_command(&self, command: &Commands) -> anyhow::Result<()> { + pub fn execute_command(&mut self, command: &Commands) -> anyhow::Result<()> { if let Commands::Archive = command { if !self.get_current_path().is_empty() { tracing::debug!("archiving path: {:?}", self.get_current_path()) } } + self.update_graph()?; + Ok(()) } @@ -163,6 +164,8 @@ impl<'a> GraphExplorer<'a> { })?; } + self.update_graph()?; + Ok(()) } } @@ -183,7 +186,13 @@ impl RenderGraph for MovementGraph { for item in &self.items { let prefix = match item.item_type { GraphItemType::Section => "- ", - GraphItemType::Item => "- [ ] ", + GraphItemType::Item { done } => { + if done { + "- [x]" + } else { + "- [ ]" + } + } }; match items.split_first().map(|(first, rest)| { @@ -241,8 +250,14 @@ impl RenderGraph for MovementGraph { for item in &self.items { let prefix = match item.item_type { - GraphItemType::Section => "- ", - GraphItemType::Item => "- [ ] ", + GraphItemType::Section => "-", + GraphItemType::Item { done } => { + if done { + "- [x]" + } else { + "- [ ]" + } + } }; match items.split_first().map(|(first, rest)| { if item.index == *first { @@ -314,7 +329,7 @@ impl<'a> StatefulWidget for GraphExplorer<'a> { #[derive(PartialEq, Eq, Debug, Clone)] enum GraphItemType { Section, - Item, + Item { done: bool }, } #[derive(PartialEq, Eq, Debug, Clone)] @@ -429,7 +444,9 @@ impl From for MovementGraph { item_type: match value.deref() { GraphItem::User(_) => GraphItemType::Section, GraphItem::Section(_) => GraphItemType::Section, - GraphItem::Item { .. } => GraphItemType::Item, + GraphItem::Item { state, .. } => GraphItemType::Item { + done: matches!(state, ItemState::Done), + }, }, }) .collect::>(); @@ -539,13 +556,13 @@ mod test { index: 0, name: "010".into(), values: MovementGraph::default(), - item_type: GraphItemType::Item, + item_type: GraphItemType::Item { done: false }, }, MovementGraphItem { index: 1, name: "011".into(), values: MovementGraph::default(), - item_type: GraphItemType::Item, + item_type: GraphItemType::Item { done: false }, }, ] } diff --git a/demo.cast b/demo.cast new file mode 100644 index 0000000..e4ddff9 --- /dev/null +++ b/demo.cast @@ -0,0 +1,105 @@ +{"version": 2, "width": 106, "height": 35, "timestamp": 1715268076, "env": {"SHELL": "/usr/bin/zsh", "TERM": "alacritty"}} +[0.061956, "o", "\u001b[1m\u001b[7m%\u001b[27m\u001b[1m\u001b[0m \r \r"] +[0.108311, "o", "\r\u001b[0m\u001b[27m\u001b[24m\u001b[J\r\n\u001b[38;2;255;153;102mhyperlog\u001b[0m \u001b[90mmain\u001b[0m\u001b[38;2;255;153;102m \u001b[0m\u001b[38;2;255;153;102m≡ \u001b[0m\u001b[1;31mrs \u001b[0m\r\n\u001b[38;2;255;153;102m❯\u001b[0m \u001b[K"] +[0.108972, "o", "\u001b[6 q"] +[0.109631, "o", "\u001b[6 q"] +[0.109701, "o", "\u001b[?2004h"] +[1.076184, "o", "c"] +[1.077952, "o", "\b\u001b[32mc\u001b[39m"] +[1.099899, "o", "\b\u001b[32mc\u001b[39m\u001b[90mlear\u001b[39m\b\b\b\b"] +[1.16562, "o", "\b\u001b[32mc\u001b[32ma\u001b[39m\u001b[39m \u001b[39m \u001b[39m \b\b\b"] +[1.170777, "o", "\b\b\u001b[1m\u001b[31mc\u001b[1m\u001b[31ma\u001b[0m\u001b[39m"] +[1.179169, "o", "\u001b[90mrgo clean\u001b[39m\u001b[9D"] +[1.254615, "o", "\b\b\u001b[1m\u001b[31mc\u001b[1m\u001b[31ma\u001b[1m\u001b[31mr\u001b[0m\u001b[39m"] +[1.404835, "o", "\b\u001b[1m\u001b[31mr\u001b[1m\u001b[31mg\u001b[0m\u001b[39m"] +[1.511465, "o", "\b\u001b[1m\u001b[31mg\u001b[1m\u001b[31mo\u001b[0m\u001b[39m"] +[1.512482, "o", "\b\b\b\b\b\u001b[0m\u001b[32mc\u001b[0m\u001b[32ma\u001b[0m\u001b[32mr\u001b[0m\u001b[32mg\u001b[0m\u001b[32mo\u001b[39m"] +[1.554502, "o", "\b\u001b[32mo\u001b[32m \u001b[39m"] +[1.555456, "o", "\b\b\u001b[32mo\u001b[39m\u001b[39m "] +[1.722553, "o", "\u001b[39mr\u001b[39m \u001b[39m \u001b[39m \u001b[39m \b\b\b\b"] +[1.724362, "o", "\b\u001b[4mr\u001b[24m"] +[1.742164, "o", "\u001b[90mun\u001b[39m\b\b"] +[1.811359, "o", "\b\u001b[4mr\u001b[39m\u001b[4mu\u001b[24m"] +[1.813462, "o", "\b\b\u001b[24mr\u001b[24mu"] +[1.961913, "o", "\u001b[39mn"] +[2.158475, "o", "\u001b[0 q"] +[2.158606, "o", "\u001b[?2004l\r\r\n"] +[2.309291, "o", "\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: unused import: `Commands`\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0mcrates/hyperlog-tui/src/app.rs:7:37\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\r\n\u001b[0m\u001b[1m\u001b[38;5;12m7\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m command_parser::{CommandParser, Commands},\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(unused_imports)]` on by default\u001b[0m\r\n\r\n\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: method `toggle` is never used\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0mcrates/hyperlog-tui/src/app/dialog.rs:100:12\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\r\n\u001b[0m\u001b[1m\u001b[38;5;12m75\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0mimpl InputBuffer {\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m----------------\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12mmethod in this implementation\u001b[0m\r\n\u001b[0m\u001b[1m\u001b[38;5;12m...\u001b[0m\r\n\u001b[0m\u001b[1m\u001b[38;5;12m100\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m pub fn toggle(&mut self) {\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\r\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(dead_code)]` on by default\u001b[0m\r\n\r\n\u001b[1m\u001b[33mwarning\u001b[0m\u001b[1m:\u001b[0m `hyperlog-tui` (lib) generated 2 warnings (run `cargo fix --lib -p hyperlog-tui` to apply 1 suggestion)\r\n\u001b[1m\u001b[32m Finished\u001b[0m \u001b]8;;https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles\u001b\\`dev` profile [unoptimized + debuginfo]\u001b]8;;\u001b\\ target(s) in 0.09s\r\n"] +[2.315705, "o", "\u001b[1m\u001b[32m Running\u001b[0m `target/debug/hyperlog`\r\n"] +[2.324861, "o", "\u001b[?1049h"] +[2.327382, "o", "\u001b[1;1H\u001b[38;5;2mhyperlog\u001b[2;1H\u001b[39m──────────────────────────────────────────────────────────────────────────────────────────────────────────\u001b[3;1H\u001b[38;5;8m- other\u001b[5;3H- other\u001b[7;5H- other\u001b[9;7H- [ ] a\u001b[11;5H- [ ] something\u001b[13;1H- some\u001b[15;1H- something\u001b[17;3H- else\u001b[19;3H- third\u001b[35;2H\u001b[39m--\u001b[35;5HVIEW\u001b[35;10H--\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[2.579631, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[2.83217, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[3.084795, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[3.117018, "o", "\u001b[3;1H\u001b[1m\u001b[38;5;15m- other\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[3.37073, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[3.506269, "o", "\u001b[3;1H\u001b[38;5;8m- other\u001b[13;1H\u001b[1m\u001b[38;5;15m- some\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[3.759095, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[4.011929, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[4.047613, "o", "\u001b[3;1H\u001b[1m\u001b[38;5;15m- other\u001b[13;1H\u001b[22m\u001b[38;5;8m- some\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[4.300637, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[4.304359, "o", "\u001b[3;1H\u001b[38;5;8m- other\u001b[5;3H\u001b[1m\u001b[38;5;15m- other\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[4.557092, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[4.737839, "o", "\u001b[1;10H~\u001b[1;12Hcreate\u001b[1;19Hitem\u001b[3;1H┌title───────────────────────────────────────────────────────────────────────────────────────────────────┐\u001b[4;1H│\u001b[38;5;0m\u001b[48;5;5m \u001b[4;106H\u001b[39m\u001b[49m│\u001b[5;1H└────────────────────────────────────────────────────────────────────────────────────────────────────────┘\u001b[6;1H\u001b[38;5;8m┌description────────────────────────────────────────────────────────────────────────────────────────────"] +[4.737887, "o", "─┐\u001b[7;1H│ \u001b[7;7H │\u001b[8;1H└────────────────────────────────────────────────────────────────────────────────────────────────────────┘\u001b[9;7H\u001b[39m \u001b[11;5H \u001b[13;1H \u001b[15;1H \u001b[17;3H \u001b[19;3H \u001b[35;5HEDIT\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[4.990266, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[5.242663, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[5.263649, "o", "\u001b[4;2Hs\u001b[38;5;0m\u001b[48;5;5m \u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[5.336941, "o", "\u001b[4;3Ho\u001b[38;5;0m\u001b[48;5;5m \u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[5.473386, "o", "\u001b[4;4Hm\u001b[38;5;0m\u001b[48;5;5m \u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[5.546165, "o", "\u001b[4;5He\u001b[38;5;0m\u001b[48;5;5m \u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[5.684402, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[5.937063, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[6.189562, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[6.442354, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[6.694082, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[6.809652, "o", "\u001b[4;6H \u001b[35;5HVIEW\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[7.062032, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[7.106297, "o", "\u001b[35;1H: \u001b[35;5H \u001b[35;10H \u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[7.196456, "o", "\u001b[35;2Hw\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[7.255925, "o", "\u001b[35;3Hq\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[7.467764, "o", "\u001b[1;10H \u001b[1;12H \u001b[1;19H \u001b[3;1H\u001b[38;5;8m- other\u001b[39m \u001b[4;1H \u001b[4;106H \u001b[5;1H \u001b[1m\u001b[38;5;15m- other\u001b[22m\u001b[39m \u001b[6;1H \u001b[7;1H \u001b[38;5;8m-\u001b[7;7Hother\u001b[39m \u001b[8;1H \u001b[9;7H\u001b[38;5;8m- [ ] a\u001b[11;5H- [ ] some\u001b[13;5H- [ ] something\u001b[15;1H- some\u001b[17;1H- something\u001b[19;3H- else\u001b[21;3H- third\u001b[35;1H\u001b[39m --\u001b[35;5HVIEW\u001b[35;10H--\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[7.720604, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[7.973639, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[8.226784, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[8.336689, "o", "\u001b[5;3H\u001b[38;5;8m- other\u001b[7;5H\u001b[1m\u001b[38;5;15m- other\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[8.590186, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[8.773505, "o", "\u001b[7;5H\u001b[38;5;8m- other\u001b[9;7H\u001b[1m\u001b[38;5;15m- [ ] a\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[9.026085, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[9.17675, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[9.429584, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[9.643372, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[9.896858, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[9.926048, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[10.178828, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[10.273339, "o", "\u001b[7;5H\u001b[1m\u001b[38;5;15m- other\u001b[9;7H\u001b[22m\u001b[38;5;8m- [ ] a\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[10.52597, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[10.5434, "o", "\u001b[7;5H\u001b[38;5;8m- other\u001b[11;5H\u001b[1m\u001b[38;5;15m- [ ] some\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[10.796065, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[11.04899, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[11.302034, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[11.554807, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[11.697704, "o", "\u001b[11;8H\u001b[1m\u001b[38;5;15mx\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[11.951284, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[12.205311, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[12.373535, "o", "\u001b[11;5H\u001b[38;5;8m- [x] some\u001b[13;5H\u001b[1m\u001b[38;5;15m- [ ] something\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[12.626159, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[12.823931, "o", "\u001b[13;8H\u001b[1m\u001b[38;5;15mx\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[13.07613, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[13.09335, "o", "\u001b[11;5H\u001b[1m\u001b[38;5;15m- [x] some\u001b[13;5H\u001b[22m\u001b[38;5;8m- [x] something\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[13.287478, "o", "\u001b[7;5H\u001b[1m\u001b[38;5;15m- other\u001b[11;5H\u001b[22m\u001b[38;5;8m- [x] some\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[13.540166, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[13.573087, "o", "\u001b[7;5H\u001b[38;5;8m- other\u001b[9;7H\u001b[1m\u001b[38;5;15m- [ ] a\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[13.826053, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[13.903827, "o", "\u001b[9;10H\u001b[1m\u001b[38;5;15mx\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[14.156497, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[14.367096, "o", "\u001b[7;5H\u001b[1m\u001b[38;5;15m- other\u001b[9;7H\u001b[22m\u001b[38;5;8m- [x] a\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[14.594457, "o", "\u001b[5;3H\u001b[1m\u001b[38;5;15m- other\u001b[7;5H\u001b[22m\u001b[38;5;8m- other\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[14.847965, "o", "\u001b[39m\u001b[49m\u001b[59m\u001b[0m\u001b[?25l"] +[15.025229, "o", "\u001b[?1049l\u001b[?25h"] +[15.026982, "o", "\u001b[1m\u001b[7m%\u001b[27m\u001b[1m\u001b[0m \r \r"] +[15.04886, "o", "\r\u001b[0m\u001b[27m\u001b[24m\u001b[J\r\n\u001b[38;2;255;153;102mhyperlog\u001b[0m \u001b[90mmain\u001b[0m\u001b[38;2;255;153;102m \u001b[0m\u001b[38;2;255;153;102m≡ \u001b[0m\u001b[1;31mrs \u001b[0m\u001b[33m12s\u001b[0m \r\n\u001b[38;2;255;153;102m❯\u001b[0m \u001b[K"] +[15.049561, "o", "\u001b[6 q"] +[15.05028, "o", "\u001b[6 q"] +[15.050378, "o", "\u001b[?2004h"] +[16.301699, "o", "\u001b[?2004l\r\r\n"]