My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: init viewport + todo

+122 -3
+6 -2
src/tui/app.rs
··· 10 10 11 11 use crate::{ 12 12 config::Config, 13 - tui::{Event, Tui, components::Zk}, 13 + tui::{ 14 + Event, Tui, 15 + components::{Viewport, Zk}, 16 + }, 14 17 types::KastenHandle, 15 18 }; 16 19 ··· 51 54 Ok(Self { 52 55 tick_rate, 53 56 frame_rate, 54 - components: vec![Box::new(Zk::new(kh.clone()).await?)], 57 + // components: vec![Box::new(Zk::new(kh.clone()).await?)], 58 + components: vec![Box::new(Viewport::new(kh.clone()).await?)], 55 59 should_quit: false, 56 60 should_suspend: false, 57 61 config: Config::parse()?,
+8 -1
src/tui/components/mod.rs
··· 13 13 14 14 /// The zk component 15 15 mod zk; 16 + pub use zk::*; 17 + 18 + /// The todo component 19 + mod todo; 20 + pub use todo::*; 16 21 17 - pub use zk::*; 22 + /// The main view into the app 23 + mod viewport; 24 + pub use viewport::*; 18 25 19 26 /// `Component` is a trait that represents a visual and interactive element of the user interface. 20 27 ///
+43
src/tui/components/todo/mod.rs
··· 1 + use async_trait::async_trait; 2 + use ratatui::{ 3 + Frame, 4 + layout::{Constraint, Layout, Rect}, 5 + style::{Color, Stylize}, 6 + widgets::Block, 7 + }; 8 + use tokio::sync::mpsc::UnboundedSender; 9 + 10 + use crate::{ 11 + tui::{Signal, components::Component}, 12 + types::KastenHandle, 13 + }; 14 + 15 + pub struct Todo { 16 + signal_tx: Option<UnboundedSender<Signal>>, 17 + kh: KastenHandle, 18 + layouts: Layouts, 19 + } 20 + 21 + struct Layouts { 22 + main: Layout, 23 + } 24 + 25 + impl Default for Layouts { 26 + fn default() -> Self { 27 + Self { 28 + main: Layout::horizontal(vec![Constraint::Percentage(50), Constraint::Percentage(50)]), 29 + } 30 + } 31 + } 32 + 33 + #[async_trait] 34 + impl Component for Todo { 35 + async fn update(&mut self, signal: Signal) -> color_eyre::Result<Option<Signal>> { 36 + Ok(None) 37 + } 38 + 39 + fn draw(&mut self, frame: &mut Frame, area: Rect) -> color_eyre::Result<()> { 40 + frame.render_widget(Block::new().fg(Color::Red), area); 41 + Ok(()) 42 + } 43 + }
+65
src/tui/components/viewport/mod.rs
··· 1 + use async_trait::async_trait; 2 + use color_eyre::eyre::Result; 3 + use ratatui::{ 4 + Frame, 5 + layout::{Constraint, Layout, Rect}, 6 + style::{Color, Stylize}, 7 + widgets::Block, 8 + }; 9 + use tokio::sync::mpsc::UnboundedSender; 10 + 11 + use crate::{ 12 + tui::{Signal, components::Component}, 13 + types::KastenHandle, 14 + }; 15 + 16 + pub struct Viewport { 17 + signal_tx: Option<UnboundedSender<Signal>>, 18 + kh: KastenHandle, 19 + layouts: Layouts, 20 + } 21 + 22 + impl Viewport { 23 + pub async fn new(kh: KastenHandle) -> Result<Self> { 24 + let kt = kh.read().await; 25 + drop(kt); 26 + Ok(Self { 27 + signal_tx: None, 28 + kh, 29 + layouts: Layouts::default(), 30 + }) 31 + } 32 + } 33 + 34 + struct Layouts { 35 + main_switcher: Layout, 36 + } 37 + 38 + impl Default for Layouts { 39 + fn default() -> Self { 40 + Self { 41 + main_switcher: Layout::vertical(vec![Constraint::Fill(90), Constraint::Min(1)]), 42 + } 43 + } 44 + } 45 + 46 + #[async_trait] 47 + impl Component for Viewport { 48 + async fn update(&mut self, signal: Signal) -> color_eyre::Result<Option<Signal>> { 49 + Ok(None) 50 + } 51 + 52 + fn draw(&mut self, frame: &mut Frame, area: Rect) -> color_eyre::Result<()> { 53 + let (main_layout, switcher_layout) = { 54 + let rects = self.layouts.main_switcher.split(area); 55 + (rects[0], rects[1]) 56 + }; 57 + 58 + // frame.render_widget(Block::new().fg(Color::Red), main_layout); 59 + // frame.render_widget(Block::new().fg(Color::Green), switcher_layout); 60 + // 61 + frame.render_widget(Block::new().bg(Color::Green), main_layout); 62 + frame.render_widget(Block::new().bg(Color::Yellow), switcher_layout); 63 + Ok(()) 64 + } 65 + }