diff --git a/flake.nix b/flake.nix index d37cbd5..a7a47ea 100644 --- a/flake.nix +++ b/flake.nix @@ -89,10 +89,11 @@ { packages.default = crate; - packages.server-only = craneLib.buildPackage { - name = name + "-server-only"; + packages."${name}-server-only" = craneLib.buildPackage { + name = "${name}-server-only"; src = ./.; - cargoExtraArgs = "--no-default-features"; + doCheck = false; + cargoExtraArgs = "--locked --no-default-features"; }; checks = { diff --git a/src/app/graph.rs b/src/app/graph.rs index 5b93a80..5dea431 100644 --- a/src/app/graph.rs +++ b/src/app/graph.rs @@ -6,12 +6,22 @@ use crate::app; const CYAN: Color = Color::from_rgb8(0, 255, 255); -#[derive(Default)] pub struct Graph { timeline: VecDeque, + pub show_borders: bool, pub cache: canvas::Cache, } +impl Default for Graph { + fn default() -> Self { + Self { + show_borders: true, + + timeline: Default::default(), + cache: Default::default(), + } + } +} impl Graph { pub fn new(value: f32) -> Self { @@ -46,16 +56,19 @@ impl canvas::Program for Graph { _cursor: mouse::Cursor, ) -> Vec> { let geometry = self.cache.draw(renderer, bounds.size(), |frame| { - frame.stroke_rectangle( - Point::new(0., 0.), - bounds.size(), - canvas::Stroke::default().with_color(Color::from_rgb8(255, 0, 0)), - ); + if self.show_borders { + frame.stroke_rectangle( + Point::new(0., 0.), + bounds.size(), + canvas::Stroke::default().with_color(Color::from_rgb8(255, 0, 0)), + ); + } frame.stroke( &canvas::Path::new(|builder| { for (index, value) in self.timeline.iter().enumerate() { let x = index as f32 / self.timeline.len() as f32 * bounds.width; - let y = bounds.height - value / 100. * bounds.height - 1.; + let y = (bounds.height - value / 100. * bounds.height) + .clamp(1., bounds.height - 1.); builder.line_to(Point::new(x, y)) } }), diff --git a/src/app/mod.rs b/src/app/mod.rs index 34d2e37..c46d289 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -53,9 +53,18 @@ impl State { } fn update(&mut self, message: Message) -> Task { match message { - Message::ToggleMain => self.is_main_section_shown.toggle(), - Message::ToggleCpu => self.is_cpu_section_shown.toggle(), - Message::ToggleMemory => self.is_memory_section_shown.toggle(), + Message::ToggleMain => { + self.is_main_section_shown.toggle(); + self.check_borders(); + } + Message::ToggleCpu => { + self.is_cpu_section_shown.toggle(); + self.check_borders(); + } + Message::ToggleMemory => { + self.is_memory_section_shown.toggle(); + self.check_borders(); + } Message::Info(snapshot) => { self.uptime = snapshot.uptime(); @@ -75,10 +84,10 @@ impl State { .map(|value| Graph::new(value)) .collect(); } else { - for (graph, value) in self.cpu_graphs.iter_mut().zip(snapshot.cpus.into_iter()) - { - graph.update(value); - } + self.cpu_graphs + .iter_mut() + .zip(snapshot.cpus.into_iter()) + .for_each(|(graph, value)| graph.update(value)); } } } @@ -140,6 +149,11 @@ impl State { fn title(&self) -> String { format!("itop {:?}", self.uptime) } + + fn check_borders(&mut self) { + self.total_cpu_graph.show_borders = + self.is_cpu_section_shown || self.is_memory_section_shown; + } } pub fn run() -> Result<(), Error> {