diff options
author | Julian T. <julian@jtle.dk> | 2024-04-29 22:25:47 +0200 |
---|---|---|
committer | Julian T. <julian@jtle.dk> | 2024-04-29 22:25:47 +0200 |
commit | 22c8553af68c6f5b2c62ba790e06b249ac82ed2a (patch) | |
tree | 27f954840087372f315311b4d202c2b20c3526b5 /src/render.rs | |
parent | 0b29e9b14607f3226c46f75a20f11abd49c8f4a6 (diff) |
Add beginnning ui and database
Diffstat (limited to 'src/render.rs')
-rw-r--r-- | src/render.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/render.rs b/src/render.rs new file mode 100644 index 0000000..8c9ce38 --- /dev/null +++ b/src/render.rs @@ -0,0 +1,66 @@ +use std::io; + +use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind}; +use ratatui::{ + buffer::Buffer, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::Stylize, symbols::border, text::Text, widgets::{block::Title, Block, Borders, Paragraph, Widget}, Frame +}; + +use crate::tui; + +use self::footer::Footer; + +mod footer; + +#[derive(Debug, Default)] +pub struct App { + exit: bool, +} + +impl App { + pub fn run(&mut self, terminal: &mut tui::Tui) -> io::Result<()> { + while !self.exit { + terminal.draw(|frame| self.render_frame(frame))?; + self.handle_events()?; + } + + Ok(()) + } + + fn render_frame(&self, frame: &mut Frame) { + frame.render_widget(self, frame.size()); + } + + fn handle_events(&mut self) -> io::Result<()> { + match event::read()?{ + Event::Key(key_event) if key_event.kind == KeyEventKind::Press => { + self.handle_key_event(key_event); + } + _ => () + } + Ok(()) + } + + pub fn exit(&mut self) { + self.exit = true; + } + + fn handle_key_event(&mut self, event: KeyEvent) { + match event.code { + KeyCode::Char('q') => self.exit(), + _ => () + } + } +} + +impl Widget for &App { + fn render(self, area: Rect, buf: &mut Buffer) { + let chunks = Layout::default() + .direction(Direction::Vertical) + .constraints([ + Constraint::Min(1), + Constraint::Length(1), + ]) + .split(area); + Footer::new().render(chunks[1], buf); + } +} |