Files
battery_logger/src/tui/main.rs
2026-03-20 19:37:40 +00:00

57 lines
1.2 KiB
Rust

use std::{error::Error, process::exit, time::Duration};
use crossterm::event::{self, Event, KeyCode};
use data::{ArchivedData, Data};
use ratatui::{
layout::{self, Constraint, Flex, Layout, Rect},
prelude::Stylize,
style::Style,
text::Text,
widgets::{Block, BorderType, Borders, Paragraph},
Frame,
};
use rkyv::{deserialize, rancor};
use crate::{
component::Component,
dashboard::{Menu, MenuMsg},
};
mod component;
mod dashboard;
// -- GLOBAL APP MESSAGE --
enum AppMsg {
Menu(MenuMsg), // Wraps the Menu's specific enum
GlobalQuit,
}
#[derive(Default, Debug)]
struct App {
menu: Menu,
should_quit: bool,
}
impl App {
// The "Update" part of TEA
fn update(&mut self, msg: AppMsg) {
match msg {
AppMsg::Menu(child_msg) => self.menu.update(child_msg),
AppMsg::GlobalQuit => self.should_quit = true,
}
}
// The "View" part of TEA
fn view(&self, f: &mut Frame) {
// Centering logic we discussed earlier!
self.menu.view(f);
}
}
fn main() {
let app: App = App::default();
ratatui::run(|terminal| loop {
terminal.draw(|f| app.view(f));
});
}