Hook up TreeView to Chat
This commit is contained in:
parent
14125c1650
commit
e72fd60d16
2 changed files with 55 additions and 7 deletions
|
|
@ -1,9 +1,13 @@
|
||||||
|
mod tree;
|
||||||
|
|
||||||
use crossterm::event::KeyEvent;
|
use crossterm::event::KeyEvent;
|
||||||
use crossterm::style::ContentStyle;
|
use crossterm::style::ContentStyle;
|
||||||
use toss::frame::{Frame, Pos, Size};
|
use toss::frame::{Frame, Pos, Size};
|
||||||
|
|
||||||
use crate::traits::{Msg, MsgStore};
|
use crate::traits::{Msg, MsgStore};
|
||||||
|
|
||||||
|
use self::tree::TreeView;
|
||||||
|
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
Tree,
|
Tree,
|
||||||
// Thread,
|
// Thread,
|
||||||
|
|
@ -11,10 +15,10 @@ pub enum Mode {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Chat<M: Msg, S: MsgStore<M>> {
|
pub struct Chat<M: Msg, S: MsgStore<M>> {
|
||||||
cursor: Option<M::Id>,
|
|
||||||
store: S,
|
store: S,
|
||||||
|
cursor: Option<M::Id>,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
// tree: TreeView,
|
tree: TreeView,
|
||||||
// thread: ThreadView,
|
// thread: ThreadView,
|
||||||
// flat: FlatView,
|
// flat: FlatView,
|
||||||
}
|
}
|
||||||
|
|
@ -22,20 +26,27 @@ pub struct Chat<M: Msg, S: MsgStore<M>> {
|
||||||
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
|
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
|
||||||
pub fn new(store: S) -> Self {
|
pub fn new(store: S) -> Self {
|
||||||
Self {
|
Self {
|
||||||
cursor: None,
|
|
||||||
store,
|
store,
|
||||||
|
cursor: None,
|
||||||
mode: Mode::Tree,
|
mode: Mode::Tree,
|
||||||
|
tree: TreeView::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
|
impl<M: Msg, S: MsgStore<M>> Chat<M, S> {
|
||||||
pub fn handle_key_event(&mut self, key: KeyEvent, size: Size) {
|
pub fn handle_key_event(&mut self, event: KeyEvent, size: Size) {
|
||||||
// TODO
|
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) {
|
pub fn render(&mut self, frame: &mut Frame, pos: Pos, size: Size) {
|
||||||
// TODO
|
match self.mode {
|
||||||
frame.write(Pos::new(0, 0), "Hello world!", ContentStyle::default());
|
Mode::Tree => self.tree.render(&mut self.store, frame, pos, size),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
37
cove-tui/src/chat/tree.rs
Normal file
37
cove-tui/src/chat/tree.rs
Normal file
|
|
@ -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<M, S>(
|
||||||
|
&mut self,
|
||||||
|
store: &mut S,
|
||||||
|
cursor: &mut Option<M::Id>,
|
||||||
|
event: KeyEvent,
|
||||||
|
size: Size,
|
||||||
|
) where
|
||||||
|
M: Msg,
|
||||||
|
S: MsgStore<M>,
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render<M: Msg, S: MsgStore<M>>(
|
||||||
|
&mut self,
|
||||||
|
store: &mut S,
|
||||||
|
frame: &mut Frame,
|
||||||
|
pos: Pos,
|
||||||
|
size: Size,
|
||||||
|
) {
|
||||||
|
// TODO
|
||||||
|
frame.write(Pos::new(0, 0), "Hello world!", ContentStyle::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue