Compare commits

..
3 changed files with 17 additions and 45 deletions

View file

@ -89,11 +89,10 @@
{ {
packages.default = crate; packages.default = crate;
packages."${name}-server-only" = craneLib.buildPackage { packages.server-only = craneLib.buildPackage {
name = "${name}-server-only"; name = name + "-server-only";
src = ./.; src = ./.;
doCheck = false; cargoExtraArgs = "--no-default-features";
cargoExtraArgs = "--locked --no-default-features";
}; };
checks = { checks = {

View file

@ -6,22 +6,12 @@ use crate::app;
const CYAN: Color = Color::from_rgb8(0, 255, 255); const CYAN: Color = Color::from_rgb8(0, 255, 255);
#[derive(Default)]
pub struct Graph { pub struct Graph {
timeline: VecDeque<f32>, timeline: VecDeque<f32>,
pub show_borders: bool,
pub cache: canvas::Cache, pub cache: canvas::Cache,
} }
impl Default for Graph {
fn default() -> Self {
Self {
show_borders: true,
timeline: Default::default(),
cache: Default::default(),
}
}
}
impl Graph { impl Graph {
pub fn new(value: f32) -> Self { pub fn new(value: f32) -> Self {
@ -56,19 +46,16 @@ impl canvas::Program<app::Message, Theme, Renderer> for Graph {
_cursor: mouse::Cursor, _cursor: mouse::Cursor,
) -> Vec<canvas::Geometry<Renderer>> { ) -> Vec<canvas::Geometry<Renderer>> {
let geometry = self.cache.draw(renderer, bounds.size(), |frame| { let geometry = self.cache.draw(renderer, bounds.size(), |frame| {
if self.show_borders {
frame.stroke_rectangle( frame.stroke_rectangle(
Point::new(0., 0.), Point::new(0., 0.),
bounds.size(), bounds.size(),
canvas::Stroke::default().with_color(Color::from_rgb8(255, 0, 0)), canvas::Stroke::default().with_color(Color::from_rgb8(255, 0, 0)),
); );
}
frame.stroke( frame.stroke(
&canvas::Path::new(|builder| { &canvas::Path::new(|builder| {
for (index, value) in self.timeline.iter().enumerate() { for (index, value) in self.timeline.iter().enumerate() {
let x = index as f32 / self.timeline.len() as f32 * bounds.width; let x = index as f32 / self.timeline.len() as f32 * bounds.width;
let y = (bounds.height - value / 100. * bounds.height) let y = bounds.height - value / 100. * bounds.height - 1.;
.clamp(1., bounds.height - 1.);
builder.line_to(Point::new(x, y)) builder.line_to(Point::new(x, y))
} }
}), }),

View file

@ -53,18 +53,9 @@ impl State {
} }
fn update(&mut self, message: Message) -> Task<Message> { fn update(&mut self, message: Message) -> Task<Message> {
match message { match message {
Message::ToggleMain => { Message::ToggleMain => self.is_main_section_shown.toggle(),
self.is_main_section_shown.toggle(); Message::ToggleCpu => self.is_cpu_section_shown.toggle(),
self.check_borders(); Message::ToggleMemory => self.is_memory_section_shown.toggle(),
}
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) => { Message::Info(snapshot) => {
self.uptime = snapshot.uptime(); self.uptime = snapshot.uptime();
@ -84,10 +75,10 @@ impl State {
.map(|value| Graph::new(value)) .map(|value| Graph::new(value))
.collect(); .collect();
} else { } else {
self.cpu_graphs for (graph, value) in self.cpu_graphs.iter_mut().zip(snapshot.cpus.into_iter())
.iter_mut() {
.zip(snapshot.cpus.into_iter()) graph.update(value);
.for_each(|(graph, value)| graph.update(value)); }
} }
} }
} }
@ -149,11 +140,6 @@ impl State {
fn title(&self) -> String { fn title(&self) -> String {
format!("itop {:?}", self.uptime) 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> { pub fn run() -> Result<(), Error> {