diff --git a/src/app/cpu_graph.rs b/src/app/graph.rs similarity index 86% rename from src/app/cpu_graph.rs rename to src/app/graph.rs index 42a4a22..8a3796a 100644 --- a/src/app/cpu_graph.rs +++ b/src/app/graph.rs @@ -7,21 +7,21 @@ use crate::app; const CYAN: Color = Color::from_rgb8(0, 255, 255); #[derive(Default)] -pub struct CpuGraph { +pub struct Graph { pub cache: canvas::Cache, timeline: VecDeque, } -impl CpuGraph { - pub fn update(&mut self, usage: f32) { - self.timeline.push_back(usage); +impl Graph { + pub fn update(&mut self, value: f32) { + self.timeline.push_back(value); if self.timeline.len() > 1000 { self.timeline.pop_front(); } } } -impl canvas::Program for CpuGraph { +impl canvas::Program for Graph { type State = (); fn draw( &self, diff --git a/src/app/mod.rs b/src/app/mod.rs index 1e0262a..f48d29a 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,19 +1,19 @@ use iced::{ - Color, Element, Length, Renderer, Task, Theme, application, futures::SinkExt, stream::channel, - theme, widget, + Color, Element, Length, Renderer, Task, Theme, application, futures::SinkExt, stream, theme, + widget, }; use smol::Timer; -use crate::app::cpu_graph::CpuGraph; +use crate::app::graph::Graph; -mod cpu_graph; +mod graph; enum Message { Cpu(f32), } struct State { - cpu_graph: CpuGraph, + cpu_graph: Graph, } impl State { @@ -23,7 +23,7 @@ impl State { cpu_graph: Default::default(), }, Task::run( - channel(1, async |mut sender| { + stream::channel(1, async |mut sender| { let mut sys = sysinfo::System::new(); let refreshes = sysinfo::RefreshKind::nothing() .with_cpu(sysinfo::CpuRefreshKind::nothing().with_cpu_usage());