diff --git a/src/main.rs b/src/main.rs index 10fd951..f107981 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,12 @@ use crossterm::event::{Event, EventStream, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; use futures::{FutureExt, StreamExt}; + use ratatui::{ - DefaultTerminal, Frame, buffer::Buffer, style::Stylize, text::Line, widgets::{Block, Gauge, Paragraph, Widget} + DefaultTerminal, Frame, + prelude::*, + style::Stylize, + text::Line, + widgets::{Block, Paragraph}, }; fn main() { @@ -19,6 +24,19 @@ pub struct App { running: bool, // Event stream. event_stream: EventStream, + state: AppState, +} + +#[derive(Debug, Default)] +pub enum screen { + #[default] + Dashboard, + Battery, +} + +#[derive(Debug, Default)] +pub struct AppState { + active_screen: screen, } impl App { @@ -42,7 +60,7 @@ impl App { /// This is where you add new widgets. See the following resources for more information: /// - /// - - fn draw(&mut self, frame: &mut Frame, buf &mut Buffer) { + fn draw(&mut self, frame: &mut Frame) { let title = Line::from("Ratatui Simple Template") .bold() .blue() @@ -50,7 +68,22 @@ impl App { let text = "Hello, Ratatui!\n\n\ Created using https://github.com/ratatui/templates\n\ Press `Esc`, `Ctrl-C` or `q` to stop running."; - frame.render_widget(); + let layout = Layout::default() + .direction(Direction::Vertical) + .constraints(vec![ + Constraint::Percentage(33), + Constraint::Percentage(33), + Constraint::Percentage(33), + ]) + .split(frame.area()); + frame.render_widget( + Paragraph::new(text) + .block(Block::bordered().title(title)) + .centered(), + layout[1], + ) + } + /// Reads the crossterm events and updates the state of [`App`]. async fn handle_crossterm_events(&mut self) -> color_eyre::Result<()> { let event = self.event_stream.next().fuse().await;