diff --git a/flake.nix b/flake.nix index a7a47ea..d37cbd5 100644 --- a/flake.nix +++ b/flake.nix @@ -89,11 +89,10 @@ { packages.default = crate; - packages."${name}-server-only" = craneLib.buildPackage { - name = "${name}-server-only"; + packages.server-only = craneLib.buildPackage { + name = name + "-server-only"; src = ./.; - doCheck = false; - cargoExtraArgs = "--locked --no-default-features"; + cargoExtraArgs = "--no-default-features"; }; checks = { diff --git a/src/app/graph.rs b/src/app/graph.rs index 5dea431..5b93a80 100644 --- a/src/app/graph.rs +++ b/src/app/graph.rs @@ -6,22 +6,12 @@ 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 { @@ -56,19 +46,16 @@ impl canvas::Program for Graph { _cursor: mouse::Cursor, ) -> Vec> { let geometry = self.cache.draw(renderer, bounds.size(), |frame| { - 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_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) - .clamp(1., bounds.height - 1.); + let y = bounds.height - value / 100. * bounds.height - 1.; builder.line_to(Point::new(x, y)) } }), diff --git a/src/app/mod.rs b/src/app/mod.rs index c46d289..34d2e37 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -53,18 +53,9 @@ impl State { } fn update(&mut self, message: Message) -> Task { match message { - 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::ToggleMain => self.is_main_section_shown.toggle(), + Message::ToggleCpu => self.is_cpu_section_shown.toggle(), + Message::ToggleMemory => self.is_memory_section_shown.toggle(), Message::Info(snapshot) => { self.uptime = snapshot.uptime(); @@ -84,10 +75,10 @@ impl State { .map(|value| Graph::new(value)) .collect(); } else { - self.cpu_graphs - .iter_mut() - .zip(snapshot.cpus.into_iter()) - .for_each(|(graph, value)| graph.update(value)); + for (graph, value) in self.cpu_graphs.iter_mut().zip(snapshot.cpus.into_iter()) + { + graph.update(value); + } } } } @@ -149,11 +140,6 @@ 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> {