From e72fd60d1699e965e9f385845c52063da05d561f Mon Sep 17 00:00:00 2001 From: Joscha Date: Mon, 13 Jun 2022 10:27:15 +0200 Subject: [PATCH] Hook up TreeView to Chat --- cove-tui/src/chat.rs | 25 ++++++++++++++++++------- cove-tui/src/chat/tree.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 cove-tui/src/chat/tree.rs diff --git a/cove-tui/src/chat.rs b/cove-tui/src/chat.rs index b291e9b..ce61cc7 100644 --- a/cove-tui/src/chat.rs +++ b/cove-tui/src/chat.rs @@ -1,9 +1,13 @@ +mod tree; + use crossterm::event::KeyEvent; use crossterm::style::ContentStyle; use toss::frame::{Frame, Pos, Size}; use crate::traits::{Msg, MsgStore}; +use self::tree::TreeView; + pub enum Mode { Tree, // Thread, @@ -11,10 +15,10 @@ pub enum Mode { } pub struct Chat> { - cursor: Option, store: S, + cursor: Option, mode: Mode, - // tree: TreeView, + tree: TreeView, // thread: ThreadView, // flat: FlatView, } @@ -22,20 +26,27 @@ pub struct Chat> { impl> Chat { pub fn new(store: S) -> Self { Self { - cursor: None, store, + cursor: None, mode: Mode::Tree, + tree: TreeView::new(), } } } impl> Chat { - pub fn handle_key_event(&mut self, key: KeyEvent, size: Size) { - // TODO + pub fn handle_key_event(&mut self, event: KeyEvent, size: Size) { + match self.mode { + Mode::Tree => { + self.tree + .handle_key_event(&mut self.store, &mut self.cursor, event, size) + } + } } pub fn render(&mut self, frame: &mut Frame, pos: Pos, size: Size) { - // TODO - frame.write(Pos::new(0, 0), "Hello world!", ContentStyle::default()); + match self.mode { + Mode::Tree => self.tree.render(&mut self.store, frame, pos, size), + } } } diff --git a/cove-tui/src/chat/tree.rs b/cove-tui/src/chat/tree.rs new file mode 100644 index 0000000..61405b8 --- /dev/null +++ b/cove-tui/src/chat/tree.rs @@ -0,0 +1,37 @@ +use crossterm::event::KeyEvent; +use crossterm::style::ContentStyle; +use toss::frame::{Frame, Pos, Size}; + +use crate::traits::{Msg, MsgStore}; + +pub struct TreeView {} + +impl TreeView { + pub fn new() -> Self { + Self {} + } + + pub fn handle_key_event( + &mut self, + store: &mut S, + cursor: &mut Option, + event: KeyEvent, + size: Size, + ) where + M: Msg, + S: MsgStore, + { + // TODO + } + + pub fn render>( + &mut self, + store: &mut S, + frame: &mut Frame, + pos: Pos, + size: Size, + ) { + // TODO + frame.write(Pos::new(0, 0), "Hello world!", ContentStyle::default()); + } +}