mirror of
https://github.com/ClementTsang/bottom.git
synced 2024-11-28 19:12:43 +03:00
Dealt with canvas a bit more, removed some redundant code.
This commit is contained in:
parent
afe9349573
commit
691c887b56
@ -8,6 +8,8 @@ use tui::{
|
|||||||
|
|
||||||
const COLOUR_LIST : [Color; 6] = [Color::LightRed, Color::LightGreen, Color::LightYellow, Color::LightBlue, Color::LightCyan, Color::LightMagenta];
|
const COLOUR_LIST : [Color; 6] = [Color::LightRed, Color::LightGreen, Color::LightYellow, Color::LightBlue, Color::LightCyan, Color::LightMagenta];
|
||||||
const TEXT_COLOUR : Color = Color::Gray;
|
const TEXT_COLOUR : Color = Color::Gray;
|
||||||
|
const GRAPH_COLOUR : Color = Color::Gray;
|
||||||
|
const BORDER_STYLE_COLOUR : Color = Color::Gray;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CanvasData {
|
pub struct CanvasData {
|
||||||
@ -21,6 +23,8 @@ pub struct CanvasData {
|
|||||||
|
|
||||||
// TODO: Change the error
|
// TODO: Change the error
|
||||||
pub fn draw_data<B : tui::backend::Backend>(terminal : &mut Terminal<B>, canvas_data : &CanvasData) -> Result<(), io::Error> {
|
pub fn draw_data<B : tui::backend::Backend>(terminal : &mut Terminal<B>, canvas_data : &CanvasData) -> Result<(), io::Error> {
|
||||||
|
let border_style : Style = Style::default().fg(BORDER_STYLE_COLOUR);
|
||||||
|
|
||||||
let temperature_rows = canvas_data.temp_sensor_data.iter().map(|sensor| Row::StyledData(sensor.iter(), Style::default().fg(TEXT_COLOUR)));
|
let temperature_rows = canvas_data.temp_sensor_data.iter().map(|sensor| Row::StyledData(sensor.iter(), Style::default().fg(TEXT_COLOUR)));
|
||||||
let disk_rows = canvas_data.disk_data.iter().map(|disk| Row::StyledData(disk.iter(), Style::default().fg(TEXT_COLOUR)));
|
let disk_rows = canvas_data.disk_data.iter().map(|disk| Row::StyledData(disk.iter(), Style::default().fg(TEXT_COLOUR)));
|
||||||
let process_rows = canvas_data.process_data.iter().map(|process| Row::StyledData(process.iter(), Style::default().fg(TEXT_COLOUR)));
|
let process_rows = canvas_data.process_data.iter().map(|process| Row::StyledData(process.iter(), Style::default().fg(TEXT_COLOUR)));
|
||||||
@ -80,8 +84,8 @@ pub fn draw_data<B : tui::backend::Backend>(terminal : &mut Terminal<B>, canvas_
|
|||||||
|
|
||||||
// CPU usage graph
|
// CPU usage graph
|
||||||
{
|
{
|
||||||
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(Color::White)).bounds([0.0, 60.0]);
|
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 60.0]);
|
||||||
let y_axis = Axis::default().style(Style::default().fg(Color::White)).bounds([0.0, 100.0]).labels(&["0.0", "50.0", "100.0"]);
|
let y_axis = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 100.0]).labels(&["0.0", "50.0", "100.0"]);
|
||||||
|
|
||||||
let mut dataset_vector : Vec<Dataset> = Vec::new();
|
let mut dataset_vector : Vec<Dataset> = Vec::new();
|
||||||
for (i, cpu) in canvas_data.cpu_data.iter().enumerate() {
|
for (i, cpu) in canvas_data.cpu_data.iter().enumerate() {
|
||||||
@ -95,7 +99,7 @@ pub fn draw_data<B : tui::backend::Backend>(terminal : &mut Terminal<B>, canvas_
|
|||||||
}
|
}
|
||||||
|
|
||||||
Chart::default()
|
Chart::default()
|
||||||
.block(Block::default().title("CPU Usage").borders(Borders::ALL))
|
.block(Block::default().title("CPU Usage").borders(Borders::ALL).border_style(border_style))
|
||||||
.x_axis(x_axis)
|
.x_axis(x_axis)
|
||||||
.y_axis(y_axis)
|
.y_axis(y_axis)
|
||||||
.datasets(&dataset_vector)
|
.datasets(&dataset_vector)
|
||||||
@ -104,10 +108,10 @@ pub fn draw_data<B : tui::backend::Backend>(terminal : &mut Terminal<B>, canvas_
|
|||||||
|
|
||||||
//Memory usage graph
|
//Memory usage graph
|
||||||
{
|
{
|
||||||
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(Color::White)).bounds([0.0, 60.0]);
|
let x_axis : Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 60.0]);
|
||||||
let y_axis = Axis::default().style(Style::default().fg(Color::White)).bounds([0.0, 100.0]).labels(&["0.0", "50.0", "100.0"]);
|
let y_axis = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 100.0]).labels(&["0.0", "50.0", "100.0"]);
|
||||||
Chart::default()
|
Chart::default()
|
||||||
.block(Block::default().title("Memory Usage").borders(Borders::ALL))
|
.block(Block::default().title("Memory Usage").borders(Borders::ALL).border_style(border_style))
|
||||||
.x_axis(x_axis)
|
.x_axis(x_axis)
|
||||||
.y_axis(y_axis)
|
.y_axis(y_axis)
|
||||||
.datasets(&[
|
.datasets(&[
|
||||||
@ -126,31 +130,39 @@ pub fn draw_data<B : tui::backend::Backend>(terminal : &mut Terminal<B>, canvas_
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Network graph
|
// Network graph
|
||||||
Block::default().title("Network").borders(Borders::ALL).render(&mut f, middle_chunks[1]);
|
Block::default().title("Network").borders(Borders::ALL).border_style(border_style).render(&mut f, middle_chunks[1]);
|
||||||
|
|
||||||
// Temperature table
|
// Temperature table
|
||||||
Table::new(["Sensor", "Temperature"].iter(), temperature_rows)
|
Table::new(["Sensor", "Temperature"].iter(), temperature_rows)
|
||||||
.block(Block::default().title("Temperatures").borders(Borders::ALL))
|
.block(Block::default().title("Temperatures").borders(Borders::ALL).border_style(border_style))
|
||||||
.header_style(Style::default().fg(Color::LightBlue))
|
.header_style(Style::default().fg(Color::LightBlue))
|
||||||
.widths(&[15, 5])
|
.widths(&[15, 5])
|
||||||
.render(&mut f, bottom_divided_chunk_1_1[0]);
|
.render(&mut f, bottom_divided_chunk_1_1[0]);
|
||||||
|
|
||||||
// Disk usage table
|
// Disk usage table
|
||||||
Table::new(["Disk", "Mount", "Used", "Total", "Free"].iter(), disk_rows)
|
Table::new(["Disk", "Mount", "Used", "Total", "Free"].iter(), disk_rows)
|
||||||
.block(Block::default().title("Disk Usage").borders(Borders::ALL))
|
.block(Block::default().title("Disk Usage").borders(Borders::ALL).border_style(border_style))
|
||||||
.header_style(Style::default().fg(Color::LightBlue))
|
.header_style(Style::default().fg(Color::LightBlue))
|
||||||
.widths(&[15, 10, 5, 5, 5])
|
.widths(&[15, 10, 5, 5, 5])
|
||||||
.render(&mut f, bottom_divided_chunk_1_2[0]);
|
.render(&mut f, bottom_divided_chunk_1_2[0]);
|
||||||
|
|
||||||
// Temp graph
|
// Temp graph
|
||||||
Block::default().title("Temperatures").borders(Borders::ALL).render(&mut f, bottom_divided_chunk_1_1[1]);
|
Block::default()
|
||||||
|
.title("Temperatures")
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_style(border_style)
|
||||||
|
.render(&mut f, bottom_divided_chunk_1_1[1]);
|
||||||
|
|
||||||
// IO graph
|
// IO graph
|
||||||
Block::default().title("IO Usage").borders(Borders::ALL).render(&mut f, bottom_divided_chunk_1_2[1]);
|
Block::default()
|
||||||
|
.title("IO Usage")
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_style(border_style)
|
||||||
|
.render(&mut f, bottom_divided_chunk_1_2[1]);
|
||||||
|
|
||||||
// Processes table
|
// Processes table
|
||||||
Table::new(["PID", "Name", "CPU%", "Mem%"].iter(), process_rows)
|
Table::new(["PID", "Name", "CPU%", "Mem%"].iter(), process_rows)
|
||||||
.block(Block::default().title("Processes").borders(Borders::ALL))
|
.block(Block::default().title("Processes").borders(Borders::ALL).border_style(border_style))
|
||||||
.header_style(Style::default().fg(Color::LightBlue))
|
.header_style(Style::default().fg(Color::LightBlue))
|
||||||
.widths(&[5, 15, 10, 10])
|
.widths(&[5, 15, 10, 10])
|
||||||
.render(&mut f, bottom_chunks[1]);
|
.render(&mut f, bottom_chunks[1]);
|
||||||
|
@ -197,16 +197,7 @@ fn update_cpu_data_points(app_data : &app::Data) -> Vec<(String, Vec<(f64, f64)>
|
|||||||
let mut this_cpu_data : Vec<(f64, f64)> = Vec::new();
|
let mut this_cpu_data : Vec<(f64, f64)> = Vec::new();
|
||||||
|
|
||||||
for cpu in &app_data.list_of_cpu_packages {
|
for cpu in &app_data.list_of_cpu_packages {
|
||||||
// To make it look better...
|
|
||||||
let current_cpu_usage = cpu.cpu_vec[cpu_num].cpu_usage;
|
let current_cpu_usage = cpu.cpu_vec[cpu_num].cpu_usage;
|
||||||
|
|
||||||
if !this_cpu_data.is_empty() {
|
|
||||||
let previous_entry_cpu_usage = this_cpu_data.last().unwrap().1;
|
|
||||||
let middling_cpu_usage = (previous_entry_cpu_usage + current_cpu_usage) / 2_f64;
|
|
||||||
|
|
||||||
this_cpu_data.push((STALE_MAX_SECONDS as f64 - current_time.duration_since(cpu.instant).as_secs_f64().floor() - 0.5_f64, middling_cpu_usage));
|
|
||||||
}
|
|
||||||
|
|
||||||
this_cpu_data.push((STALE_MAX_SECONDS as f64 - current_time.duration_since(cpu.instant).as_secs_f64().floor(), current_cpu_usage));
|
this_cpu_data.push((STALE_MAX_SECONDS as f64 - current_time.duration_since(cpu.instant).as_secs_f64().floor(), current_cpu_usage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user