Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
5acc09b471 |
|||
|
cb2461b64f |
|||
|
d3f94b4acc |
|||
|
d1fb0ca78a |
3 changed files with 45 additions and 17 deletions
|
|
@ -89,10 +89,11 @@
|
||||||
{
|
{
|
||||||
packages.default = crate;
|
packages.default = crate;
|
||||||
|
|
||||||
packages.server-only = craneLib.buildPackage {
|
packages."${name}-server-only" = craneLib.buildPackage {
|
||||||
name = name + "-server-only";
|
name = "${name}-server-only";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
cargoExtraArgs = "--no-default-features";
|
doCheck = false;
|
||||||
|
cargoExtraArgs = "--locked --no-default-features";
|
||||||
};
|
};
|
||||||
|
|
||||||
checks = {
|
checks = {
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,22 @@ 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 {
|
||||||
|
|
@ -46,16 +56,19 @@ 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 - 1.;
|
let y = (bounds.height - value / 100. * bounds.height)
|
||||||
|
.clamp(1., bounds.height - 1.);
|
||||||
builder.line_to(Point::new(x, y))
|
builder.line_to(Point::new(x, y))
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,18 @@ impl State {
|
||||||
}
|
}
|
||||||
fn update(&mut self, message: Message) -> Task<Message> {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::ToggleMain => self.is_main_section_shown.toggle(),
|
Message::ToggleMain => {
|
||||||
Message::ToggleCpu => self.is_cpu_section_shown.toggle(),
|
self.is_main_section_shown.toggle();
|
||||||
Message::ToggleMemory => self.is_memory_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) => {
|
Message::Info(snapshot) => {
|
||||||
self.uptime = snapshot.uptime();
|
self.uptime = snapshot.uptime();
|
||||||
|
|
@ -75,10 +84,10 @@ impl State {
|
||||||
.map(|value| Graph::new(value))
|
.map(|value| Graph::new(value))
|
||||||
.collect();
|
.collect();
|
||||||
} else {
|
} else {
|
||||||
for (graph, value) in self.cpu_graphs.iter_mut().zip(snapshot.cpus.into_iter())
|
self.cpu_graphs
|
||||||
{
|
.iter_mut()
|
||||||
graph.update(value);
|
.zip(snapshot.cpus.into_iter())
|
||||||
}
|
.for_each(|(graph, value)| graph.update(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -140,6 +149,11 @@ 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> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue