From 63cbf76b3e3f40ea8ac55f13046afb0c1b7dc8b4 Mon Sep 17 00:00:00 2001 From: Doloro1978 Date: Fri, 20 Mar 2026 12:42:04 +0000 Subject: [PATCH] ELM model init --- src/daemon/main.rs | 2 +- src/tui/data_graph.rs | 4 ++-- src/tui/main.rs | 55 ++++++++++++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/daemon/main.rs b/src/daemon/main.rs index e8a3a9e..2ac1cca 100644 --- a/src/daemon/main.rs +++ b/src/daemon/main.rs @@ -9,7 +9,7 @@ use std::{ use rkyv::{api::low::deserialize, rancor, Deserialize}; -use data::DataChunk; +use data::{ArchivedData, Data, DataChunk}; mod battery; diff --git a/src/tui/data_graph.rs b/src/tui/data_graph.rs index d559af0..1717e54 100644 --- a/src/tui/data_graph.rs +++ b/src/tui/data_graph.rs @@ -7,8 +7,8 @@ trait Graphable { } impl Graphable for SplitData { + // Timestamps are unix timestamp (seconds) fn timeframe(&self, start: u64, end: u64) -> Vec<(f64, f64)> { - let mut data: Vec<(f64, f64)> = Vec::new(); let filtered: Vec<(f64, f64)> = self .chunks .iter() @@ -20,7 +20,7 @@ impl Graphable for SplitData { } }) .collect(); - data + filtered } } diff --git a/src/tui/main.rs b/src/tui/main.rs index 5b91d6e..7e2264a 100644 --- a/src/tui/main.rs +++ b/src/tui/main.rs @@ -1,33 +1,50 @@ -use std::{process::exit, time::Duration}; +use std::{error::Error, process::exit, time::Duration}; +use data::{ArchivedData, Data}; use ratatui::{ layout::{self, Constraint, Layout}, prelude::Stylize, widgets::{Block, Borders}, + Frame, }; +use rkyv::{deserialize, rancor}; mod data_graph; +#[derive(Default, Debug)] +struct Root { + counter: i32, + running_state: RunningState, +} + +#[derive(Default, Debug)] +enum RunningState { + #[default] + Running, + Done, +} + +#[derive(PartialEq)] +enum Message { + Increment, + Decrement, + Reset, + Quit, +} + +impl Root { + fn view(&self, f: &mut Frame) { + let block = Block::new() + .border_type(ratatui::widgets::BorderType::Rounded) + .borders(Borders::ALL); + f.render_widget(block, f.area()); + } +} + fn main() -> Result<(), Box> { + let mut app = Root::default(); ratatui::run(|terminal| loop { terminal.draw(|frame| { - let layout = frame.area().layout_vec(&Layout::vertical([ - Constraint::Percentage(33), - Constraint::Percentage(33), - Constraint::Percentage(33), - ])); - let middle = layout[1].layout_vec(&Layout::horizontal([ - Constraint::Percentage(33), - Constraint::Percentage(33), - Constraint::Percentage(33), - ])); - let widget = Block::new() - .border_type(ratatui::widgets::BorderType::Rounded) - .borders(Borders::ALL) - .title("Mroew"); - frame.render_widget(widget, middle[1]); + app.view(frame); })?; - if crossterm::event::read().unwrap().is_key_press() { - break Ok(()); - }; }) }