From b02db2a0febe8b99f31d226a7eaea95260736b03 Mon Sep 17 00:00:00 2001 From: suri-codes Date: Sat, 18 Apr 2026 18:52:47 -0700 Subject: [PATCH] feat: Group and Task inspector view styles --- src/tui/app.rs | 11 +-- .../components/todo/inspector/groupview.rs | 34 ++++++--- src/tui/components/todo/inspector/taskview.rs | 69 ++++++++++++------- src/tui/components/todo/mod.rs | 5 +- src/tui/signal.rs | 4 ++ 5 files changed, 81 insertions(+), 42 deletions(-) diff --git a/src/tui/app.rs b/src/tui/app.rs index 1047c63..f7e3bf9 100644 --- a/src/tui/app.rs +++ b/src/tui/app.rs @@ -37,15 +37,18 @@ pub struct App { /// The different regions of the application that the user can /// be interacting with. Think of these kind of like the highest class of /// components. -#[derive( - Default, Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, EnumIter, Display, -)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, EnumIter, Display)] pub enum Page { - #[default] Zk, Todo(TodoRegion), } +impl Default for Page { + fn default() -> Self { + Self::Todo(TodoRegion::Explorer) + } +} + impl App { /// Construct a new `App` instance. pub fn new( diff --git a/src/tui/components/todo/inspector/groupview.rs b/src/tui/components/todo/inspector/groupview.rs index fae9639..d2e8129 100644 --- a/src/tui/components/todo/inspector/groupview.rs +++ b/src/tui/components/todo/inspector/groupview.rs @@ -1,14 +1,16 @@ use ratatui::{ layout::{Constraint, Layout}, - widgets::{Paragraph, Widget}, + style::Style, + widgets::{Block, Paragraph, Widget}, }; +use ratatui_textarea::TextArea; use crate::types::Group; #[derive(Debug, Clone)] pub struct GroupView<'text> { - name: Paragraph<'text>, - priority: Paragraph<'text>, + name: TextArea<'text>, + priority: TextArea<'text>, created_at: Paragraph<'text>, layouts: Layouts, } @@ -23,13 +25,14 @@ impl Default for Layouts { fn default() -> Self { Self { left_content: Layout::horizontal(vec![ - Constraint::Percentage(50), + Constraint::Percentage(30), Constraint::Fill(100), ]), name_priority_created_at: Layout::vertical(vec![ - Constraint::Percentage(33), - Constraint::Percentage(33), - Constraint::Percentage(33), + Constraint::Min(3), + Constraint::Min(3), + Constraint::Min(3), + Constraint::Min(3), ]), } } @@ -37,10 +40,21 @@ impl Default for Layouts { impl From<&Group> for GroupView<'_> { fn from(value: &Group) -> Self { + let mut name = TextArea::new(vec![value.name.clone()]); + name.set_block(Block::bordered().title("[N]ame")); + name.set_cursor_style(Style::reset()); + name.set_cursor_line_style(Style::reset()); + + let mut priority = TextArea::new(vec![value.priority.to_string()]); + priority.set_block(Block::bordered().title("[P]riority")); + priority.set_cursor_style(Style::reset()); + priority.set_cursor_line_style(Style::reset()); + Self { - name: Paragraph::new(value.name.clone()), - priority: Paragraph::new(value.priority.to_string()), - created_at: Paragraph::new(value.created_at()), + name, + priority, + created_at: Paragraph::new(value.created_at()) + .block(Block::bordered().title("Created At")), layouts: Layouts::default(), } } diff --git a/src/tui/components/todo/inspector/taskview.rs b/src/tui/components/todo/inspector/taskview.rs index 8f3f8bc..acff83d 100644 --- a/src/tui/components/todo/inspector/taskview.rs +++ b/src/tui/components/todo/inspector/taskview.rs @@ -1,41 +1,39 @@ use ratatui::{ layout::{Constraint, Layout}, - widgets::{Paragraph, Widget}, + style::Style, + widgets::{Block, Paragraph, Widget}, }; +use ratatui_textarea::TextArea; use crate::types::Task; #[derive(Debug, Clone)] pub struct TaskView<'text> { - name: Paragraph<'text>, - priority: Paragraph<'text>, - #[expect(dead_code)] - created_at: Paragraph<'text>, - #[expect(dead_code)] + name: TextArea<'text>, + priority: TextArea<'text>, parent_group: Paragraph<'text>, - - due: Paragraph<'text>, - + due_finished_at: Paragraph<'text>, layouts: Layouts, } #[derive(Debug, Clone)] struct Layouts { left_content: Layout, - name_priority_due: Layout, + name_priority_due_group: Layout, } impl Default for Layouts { fn default() -> Self { Self { left_content: Layout::horizontal(vec![ - Constraint::Percentage(50), + Constraint::Percentage(30), Constraint::Fill(100), ]), - name_priority_due: Layout::vertical(vec![ - Constraint::Percentage(33), - Constraint::Percentage(33), - Constraint::Percentage(33), + name_priority_due_group: Layout::vertical(vec![ + Constraint::Min(3), + Constraint::Min(3), + Constraint::Min(3), + Constraint::Min(3), ]), } } @@ -43,12 +41,34 @@ impl Default for Layouts { impl From<&Task> for TaskView<'_> { fn from(value: &Task) -> Self { + let mut name = TextArea::new(vec![value.name.clone()]); + name.set_block(Block::bordered().title("[N]ame")); + name.set_cursor_style(Style::reset()); + name.set_cursor_line_style(Style::reset()); + + let mut priority = TextArea::new(vec![value.priority.to_string()]); + priority.set_block(Block::bordered().title("[P]riority")); + priority.set_cursor_style(Style::reset()); + priority.set_cursor_line_style(Style::reset()); + + let due_finished_at = { + value.finished_at().map_or_else( + || { + value.due().map_or_else( + || Paragraph::new("None").block(Block::bordered().title("Due")), + |due| Paragraph::new(due).block(Block::bordered().title("Due")), + ) + }, + |finished| Paragraph::new(finished).block(Block::bordered().title("Finished At")), + ) + }; + Self { - name: Paragraph::new(value.name.clone()), - priority: Paragraph::new(value.priority.to_string()), - created_at: Paragraph::new(value.created_at()), - parent_group: Paragraph::new(value.group.name.clone()), - due: Paragraph::new(value.due().unwrap_or_else(|| "None".to_owned())), + name, + priority, + due_finished_at, + parent_group: Paragraph::new(value.group.name.clone()) + .block(Block::bordered().title("Group")), layouts: Layouts::default(), } } @@ -59,15 +79,16 @@ impl Widget for TaskView<'_> { where Self: Sized, { - let (name_rect, priority_rect, due_rect, _content_rect) = { + let (name_rect, priority_rect, due_rect, group_rect, _content_rect) = { let rects = self.layouts.left_content.split(area); - let l_rects = self.layouts.name_priority_due.split(rects[0]); + let l_rects = self.layouts.name_priority_due_group.split(rects[0]); - (l_rects[0], l_rects[1], l_rects[2], rects[1]) + (l_rects[0], l_rects[1], l_rects[2], l_rects[3], rects[1]) }; self.name.render(name_rect, buf); self.priority.render(priority_rect, buf); - self.due.render(due_rect, buf); + self.due_finished_at.render(due_rect, buf); + self.parent_group.render(group_rect, buf); } } diff --git a/src/tui/components/todo/mod.rs b/src/tui/components/todo/mod.rs index 3ddd570..2bfc125 100644 --- a/src/tui/components/todo/mod.rs +++ b/src/tui/components/todo/mod.rs @@ -182,10 +182,7 @@ impl Default for Layouts { Constraint::Percentage(40), Constraint::Fill(100), ]), - inspector_task_list: Layout::vertical(vec![ - Constraint::Percentage(30), - Constraint::Fill(100), - ]), + inspector_task_list: Layout::vertical(vec![Constraint::Min(16), Constraint::Fill(100)]), } } } diff --git a/src/tui/signal.rs b/src/tui/signal.rs index c2d86c7..028fa1e 100644 --- a/src/tui/signal.rs +++ b/src/tui/signal.rs @@ -65,6 +65,10 @@ pub enum Signal { /// Create a new `Task` NewTask, + /// Edit the name of a `Task` or a `Group`. + /// Only works with the inspector + EditName, + /// this is fucking temporary Helix { path: PathBuf, -- 2.51.2