40 lines
908 B
Rust
40 lines
908 B
Rust
|
use std::io::Error;
|
||
|
|
||
|
use crossterm::event::KeyCode;
|
||
|
use tui::layout::Rect;
|
||
|
|
||
|
use crate::pane::{Message, Pane};
|
||
|
use crate::directory::Directory;
|
||
|
use crate::terminal::Terminal;
|
||
|
|
||
|
pub struct State {
|
||
|
panes: Vec<Box<dyn Pane>>,
|
||
|
selected: usize,
|
||
|
}
|
||
|
impl State {
|
||
|
pub fn new() -> Self {
|
||
|
Self {
|
||
|
panes: vec![ Box::new( Directory::new("root".into()) ) ],
|
||
|
selected: 0,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn render(&self, terminal: &mut Terminal, area: Rect) -> Result<(), Error> {
|
||
|
terminal.draw(
|
||
|
|output|
|
||
|
self.panes
|
||
|
.iter()
|
||
|
.for_each(|p| p.display(output, area))
|
||
|
)?;
|
||
|
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
pub fn cursor_position(&self) -> Option<(u16, u16)> {
|
||
|
self.panes[self.selected].cursor_position()
|
||
|
}
|
||
|
|
||
|
pub fn update(&mut self, key: KeyCode) -> Message {
|
||
|
self.panes[self.selected].update(key)
|
||
|
}
|
||
|
}
|