Init Commit
This commit is contained in:
55
src/app.rs
Normal file
55
src/app.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use crate::event::{Event, EventHandler};
|
||||
use ratatui::widgets::Block;
|
||||
use ratatui::{DefaultTerminal, Frame};
|
||||
use std::time::Duration;
|
||||
use color_eyre::Result;
|
||||
use crossterm::event::KeyCode::Char;
|
||||
use ratatui::layout::Alignment;
|
||||
|
||||
pub(crate) struct App {
|
||||
running: bool,
|
||||
events: EventHandler,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> App {
|
||||
App {
|
||||
running: true,
|
||||
events: EventHandler::new(Duration::from_millis(250)),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(&mut self, mut terminal: DefaultTerminal) -> Result<()> {
|
||||
loop {
|
||||
terminal.draw(|frame| App::render(self, frame))?;
|
||||
let event = self.events.next().await?;
|
||||
self.update(event)?;
|
||||
if !self.running {
|
||||
break Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, event: Event) -> Result<()> {
|
||||
if let Event::Key(key) = event {
|
||||
match key.code {
|
||||
Char('q') => self.quit(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn quit(&mut self) {
|
||||
self.running = false;
|
||||
}
|
||||
|
||||
fn render(&mut self, frame: &mut Frame) {
|
||||
frame.render_widget(
|
||||
Block::bordered()
|
||||
.title("Sus Manager")
|
||||
.title_alignment(Alignment::Center),
|
||||
frame.area()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user