Compare commits

..
3 changed files with 17 additions and 45 deletions

View file

@ -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 = {

View file

@ -6,22 +6,12 @@ use crate::app;
const CYAN: Color = Color::from_rgb8(0, 255, 255);
#[derive(Default)]
pub struct Graph {
timeline: VecDeque<f32>,
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<app::Message, Theme, Renderer> for Graph {
_cursor: mouse::Cursor,
) -> Vec<canvas::Geometry<Renderer>> {
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(
&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))
}
}),

View file

@ -53,18 +53,9 @@ impl State {
}
fn update(&mut self, message: Message) -> Task<Message> {
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> {