45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
|
mod cell;
|
||
|
mod component;
|
||
|
mod context;
|
||
|
mod geometry;
|
||
|
mod view;
|
||
|
|
||
|
pub use cell::Cell;
|
||
|
pub use component::Component;
|
||
|
pub use context::Context;
|
||
|
pub use crossterm::style::{Color, Stylize};
|
||
|
use crossterm::terminal::enable_raw_mode;
|
||
|
pub use geometry::{Pos, Rect};
|
||
|
pub use std::io::Write;
|
||
|
pub use view::View;
|
||
|
|
||
|
use crate::Result;
|
||
|
|
||
|
pub struct UI {
|
||
|
root: Box<dyn Component>,
|
||
|
}
|
||
|
|
||
|
impl UI {
|
||
|
pub fn new<C: Component + 'static>(root: C) -> Self {
|
||
|
Self {
|
||
|
root: Box::new(root),
|
||
|
}
|
||
|
}
|
||
|
pub fn run(&mut self) -> Result<()> {
|
||
|
let mut output = std::io::stdout();
|
||
|
let mut context = Context::default();
|
||
|
loop {
|
||
|
// enable_raw_mode();
|
||
|
self.root.view(&mut context)?;
|
||
|
context.view.render(Pos::new(0, 0), &mut output)?;
|
||
|
output.flush().expect("Couldnt flush output");
|
||
|
|
||
|
let event = crossterm::event::read()?;
|
||
|
context.event = Some(event);
|
||
|
self.root.view(&mut context)?;
|
||
|
context.view.render(Pos::new(0, 0), &mut output)?;
|
||
|
output.flush().expect("Couldnt flush output");
|
||
|
}
|
||
|
}
|
||
|
}
|