mirror of
https://github.com/ClementTsang/bottom
synced 2025-02-15 12:48:28 +00:00
Rearrange to fit legend and extra info.
This commit is contained in:
parent
f7243bd78b
commit
ad4f124d9d
4 changed files with 167 additions and 107 deletions
84
src/app.rs
84
src/app.rs
|
@ -8,12 +8,12 @@ mod process_killer;
|
|||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum ApplicationPosition {
|
||||
CPU,
|
||||
MEM,
|
||||
DISK,
|
||||
TEMP,
|
||||
NETWORK,
|
||||
PROCESS,
|
||||
Cpu,
|
||||
Mem,
|
||||
Disk,
|
||||
Temp,
|
||||
Network,
|
||||
Process,
|
||||
}
|
||||
|
||||
pub enum ScrollDirection {
|
||||
|
@ -24,22 +24,23 @@ pub enum ScrollDirection {
|
|||
}
|
||||
|
||||
pub struct App {
|
||||
// Sorting
|
||||
pub process_sorting_type: processes::ProcessSorting,
|
||||
pub process_sorting_reverse: bool,
|
||||
pub to_be_resorted: bool,
|
||||
// Positioning
|
||||
pub currently_selected_process_position: i64,
|
||||
pub currently_selected_disk_position: i64,
|
||||
pub currently_selected_temperature_position: i64,
|
||||
pub temperature_type: temperature::TemperatureType,
|
||||
pub update_rate_in_milliseconds: u64,
|
||||
pub show_average_cpu: bool,
|
||||
pub current_application_position: ApplicationPosition,
|
||||
pub current_zoom_level_percent: f64, // Make at most 200, least 50?
|
||||
pub data: data_collection::Data,
|
||||
pub scroll_direction: ScrollDirection,
|
||||
pub previous_disk_position: i64,
|
||||
pub previous_temp_position: i64,
|
||||
pub previous_process_position: i64,
|
||||
pub temperature_type: temperature::TemperatureType,
|
||||
pub update_rate_in_milliseconds: u64,
|
||||
pub show_average_cpu: bool,
|
||||
pub current_application_position: ApplicationPosition,
|
||||
pub data: data_collection::Data,
|
||||
awaiting_second_char: bool,
|
||||
second_char: char,
|
||||
pub use_dot: bool,
|
||||
|
@ -63,13 +64,12 @@ impl App {
|
|||
temperature_type,
|
||||
update_rate_in_milliseconds,
|
||||
show_average_cpu,
|
||||
current_application_position: ApplicationPosition::PROCESS,
|
||||
current_zoom_level_percent: 100.0,
|
||||
data: data_collection::Data::default(),
|
||||
current_application_position: ApplicationPosition::Process,
|
||||
scroll_direction: ScrollDirection::DOWN,
|
||||
previous_process_position: 0,
|
||||
previous_disk_position: 0,
|
||||
previous_temp_position: 0,
|
||||
data: data_collection::Data::default(),
|
||||
awaiting_second_char: false,
|
||||
second_char: ' ',
|
||||
use_dot,
|
||||
|
@ -205,9 +205,9 @@ impl App {
|
|||
// PROC -(up)> Disk, -(left)> Network
|
||||
pub fn on_left(&mut self) {
|
||||
self.current_application_position = match self.current_application_position {
|
||||
ApplicationPosition::PROCESS => ApplicationPosition::NETWORK,
|
||||
ApplicationPosition::DISK => ApplicationPosition::MEM,
|
||||
ApplicationPosition::TEMP => ApplicationPosition::MEM,
|
||||
ApplicationPosition::Process => ApplicationPosition::Network,
|
||||
ApplicationPosition::Disk => ApplicationPosition::Mem,
|
||||
ApplicationPosition::Temp => ApplicationPosition::Mem,
|
||||
_ => self.current_application_position,
|
||||
};
|
||||
self.reset_multi_tap_keys();
|
||||
|
@ -215,8 +215,8 @@ impl App {
|
|||
|
||||
pub fn on_right(&mut self) {
|
||||
self.current_application_position = match self.current_application_position {
|
||||
ApplicationPosition::MEM => ApplicationPosition::TEMP,
|
||||
ApplicationPosition::NETWORK => ApplicationPosition::PROCESS,
|
||||
ApplicationPosition::Mem => ApplicationPosition::Temp,
|
||||
ApplicationPosition::Network => ApplicationPosition::Process,
|
||||
_ => self.current_application_position,
|
||||
};
|
||||
self.reset_multi_tap_keys();
|
||||
|
@ -224,11 +224,11 @@ impl App {
|
|||
|
||||
pub fn on_up(&mut self) {
|
||||
self.current_application_position = match self.current_application_position {
|
||||
ApplicationPosition::MEM => ApplicationPosition::CPU,
|
||||
ApplicationPosition::NETWORK => ApplicationPosition::MEM,
|
||||
ApplicationPosition::PROCESS => ApplicationPosition::DISK,
|
||||
ApplicationPosition::TEMP => ApplicationPosition::CPU,
|
||||
ApplicationPosition::DISK => ApplicationPosition::TEMP,
|
||||
ApplicationPosition::Mem => ApplicationPosition::Cpu,
|
||||
ApplicationPosition::Network => ApplicationPosition::Mem,
|
||||
ApplicationPosition::Process => ApplicationPosition::Disk,
|
||||
ApplicationPosition::Temp => ApplicationPosition::Cpu,
|
||||
ApplicationPosition::Disk => ApplicationPosition::Temp,
|
||||
_ => self.current_application_position,
|
||||
};
|
||||
self.reset_multi_tap_keys();
|
||||
|
@ -236,10 +236,10 @@ impl App {
|
|||
|
||||
pub fn on_down(&mut self) {
|
||||
self.current_application_position = match self.current_application_position {
|
||||
ApplicationPosition::CPU => ApplicationPosition::MEM,
|
||||
ApplicationPosition::MEM => ApplicationPosition::NETWORK,
|
||||
ApplicationPosition::TEMP => ApplicationPosition::DISK,
|
||||
ApplicationPosition::DISK => ApplicationPosition::PROCESS,
|
||||
ApplicationPosition::Cpu => ApplicationPosition::Mem,
|
||||
ApplicationPosition::Mem => ApplicationPosition::Network,
|
||||
ApplicationPosition::Temp => ApplicationPosition::Disk,
|
||||
ApplicationPosition::Disk => ApplicationPosition::Process,
|
||||
_ => self.current_application_position,
|
||||
};
|
||||
self.reset_multi_tap_keys();
|
||||
|
@ -247,20 +247,20 @@ impl App {
|
|||
|
||||
pub fn skip_to_first(&mut self) {
|
||||
match self.current_application_position {
|
||||
ApplicationPosition::PROCESS => self.currently_selected_process_position = 0,
|
||||
ApplicationPosition::TEMP => self.currently_selected_temperature_position = 0,
|
||||
ApplicationPosition::DISK => self.currently_selected_disk_position = 0,
|
||||
ApplicationPosition::Process => self.currently_selected_process_position = 0,
|
||||
ApplicationPosition::Temp => self.currently_selected_temperature_position = 0,
|
||||
ApplicationPosition::Disk => self.currently_selected_disk_position = 0,
|
||||
_ => {}
|
||||
}
|
||||
self.scroll_direction = ScrollDirection::DOWN;
|
||||
self.scroll_direction = ScrollDirection::UP;
|
||||
self.reset_multi_tap_keys();
|
||||
}
|
||||
|
||||
pub fn skip_to_last(&mut self) {
|
||||
match self.current_application_position {
|
||||
ApplicationPosition::PROCESS => self.currently_selected_process_position = self.data.list_of_processes.len() as i64 - 1,
|
||||
ApplicationPosition::TEMP => self.currently_selected_temperature_position = self.data.list_of_temperature_sensor.len() as i64 - 1,
|
||||
ApplicationPosition::DISK => self.currently_selected_disk_position = self.data.list_of_disks.len() as i64 - 1,
|
||||
ApplicationPosition::Process => self.currently_selected_process_position = self.data.list_of_processes.len() as i64 - 1,
|
||||
ApplicationPosition::Temp => self.currently_selected_temperature_position = self.data.list_of_temperature_sensor.len() as i64 - 1,
|
||||
ApplicationPosition::Disk => self.currently_selected_disk_position = self.data.list_of_disks.len() as i64 - 1,
|
||||
_ => {}
|
||||
}
|
||||
self.scroll_direction = ScrollDirection::DOWN;
|
||||
|
@ -269,9 +269,9 @@ impl App {
|
|||
|
||||
pub fn decrement_position_count(&mut self) {
|
||||
match self.current_application_position {
|
||||
ApplicationPosition::PROCESS => self.change_process_position(-1),
|
||||
ApplicationPosition::TEMP => self.change_temp_position(-1),
|
||||
ApplicationPosition::DISK => self.change_disk_position(-1),
|
||||
ApplicationPosition::Process => self.change_process_position(-1),
|
||||
ApplicationPosition::Temp => self.change_temp_position(-1),
|
||||
ApplicationPosition::Disk => self.change_disk_position(-1),
|
||||
_ => {}
|
||||
}
|
||||
self.scroll_direction = ScrollDirection::UP;
|
||||
|
@ -280,9 +280,9 @@ impl App {
|
|||
|
||||
pub fn increment_position_count(&mut self) {
|
||||
match self.current_application_position {
|
||||
ApplicationPosition::PROCESS => self.change_process_position(1),
|
||||
ApplicationPosition::TEMP => self.change_temp_position(1),
|
||||
ApplicationPosition::DISK => self.change_disk_position(1),
|
||||
ApplicationPosition::Process => self.change_process_position(1),
|
||||
ApplicationPosition::Temp => self.change_temp_position(1),
|
||||
ApplicationPosition::Disk => self.change_disk_position(1),
|
||||
_ => {}
|
||||
}
|
||||
self.scroll_direction = ScrollDirection::DOWN;
|
||||
|
|
154
src/canvas.rs
154
src/canvas.rs
|
@ -1,10 +1,10 @@
|
|||
use crate::{app, constants, utils::error, utils::gen_util::*};
|
||||
use tui::{
|
||||
backend,
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
layout::{Alignment, Constraint, Corner, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
terminal::Frame,
|
||||
widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Paragraph, Row, Table, Text, Widget},
|
||||
widgets::{Axis, Block, Borders, Chart, Dataset, List, Marker, Paragraph, Row, Table, Text, Widget},
|
||||
Terminal,
|
||||
};
|
||||
|
||||
|
@ -162,27 +162,14 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
|
|||
)
|
||||
.split(vertical_chunks[0]);
|
||||
|
||||
let mem_chunk = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.margin(0)
|
||||
.constraints(
|
||||
if app_state.left_legend {
|
||||
[Constraint::Percentage(10), Constraint::Percentage(90)]
|
||||
} else {
|
||||
[Constraint::Percentage(90), Constraint::Percentage(10)]
|
||||
}
|
||||
.as_ref(),
|
||||
)
|
||||
.split(middle_chunks[0]);
|
||||
|
||||
let network_chunk = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.direction(Direction::Vertical)
|
||||
.margin(0)
|
||||
.constraints(
|
||||
if app_state.left_legend {
|
||||
[Constraint::Percentage(10), Constraint::Percentage(90)]
|
||||
} else {
|
||||
[Constraint::Percentage(90), Constraint::Percentage(10)]
|
||||
[Constraint::Percentage(75), Constraint::Percentage(10)]
|
||||
}
|
||||
.as_ref(),
|
||||
)
|
||||
|
@ -197,17 +184,17 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
|
|||
draw_cpu_graph(&mut f, &app_state, &canvas_data.cpu_data, cpu_chunk[graph_index]);
|
||||
|
||||
// CPU label
|
||||
draw_cpu_legend(&mut f, &app_state, &canvas_data.cpu_data, cpu_chunk[legend_index]);
|
||||
|
||||
//Memory usage graph
|
||||
draw_memory_graph(&mut f, &app_state, &canvas_data.mem_data, &canvas_data.swap_data, mem_chunk[graph_index]);
|
||||
|
||||
// Memory label
|
||||
|
||||
// Temperature table
|
||||
draw_temp_table(&mut f, app_state, &canvas_data.temp_sensor_data, middle_divided_chunk_2[0]);
|
||||
|
||||
// Disk usage table
|
||||
draw_disk_table(&mut f, app_state, &canvas_data.disk_data, middle_divided_chunk_2[1]);
|
||||
draw_memory_graph(
|
||||
&mut f,
|
||||
&app_state,
|
||||
&canvas_data.memory_labels,
|
||||
&canvas_data.mem_data,
|
||||
&canvas_data.swap_data,
|
||||
middle_chunks[0],
|
||||
);
|
||||
|
||||
// Network graph
|
||||
draw_network_graph(
|
||||
|
@ -215,10 +202,24 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
|
|||
&app_state,
|
||||
&canvas_data.network_data_rx,
|
||||
&canvas_data.network_data_tx,
|
||||
network_chunk[graph_index],
|
||||
canvas_data.rx_display.clone(),
|
||||
canvas_data.tx_display.clone(),
|
||||
network_chunk[0],
|
||||
);
|
||||
|
||||
// Network label
|
||||
draw_network_labels(
|
||||
&mut f,
|
||||
app_state,
|
||||
canvas_data.total_rx_display.clone(),
|
||||
canvas_data.total_tx_display.clone(),
|
||||
network_chunk[1],
|
||||
);
|
||||
|
||||
// Temperature table
|
||||
draw_temp_table(&mut f, app_state, &canvas_data.temp_sensor_data, middle_divided_chunk_2[0]);
|
||||
|
||||
// Disk usage table
|
||||
draw_disk_table(&mut f, app_state, &canvas_data.disk_data, middle_divided_chunk_2[1]);
|
||||
|
||||
// Processes table
|
||||
draw_processes_table(&mut f, app_state, &canvas_data.process_data, bottom_chunks[1]);
|
||||
|
@ -254,7 +255,6 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, c
|
|||
|
||||
dataset_vector.push(
|
||||
Dataset::default()
|
||||
.name(&cpu.0)
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.style(Style::default().fg(COLOUR_LIST[(i - avg_cpu_exist_offset) % COLOUR_LIST.len()]))
|
||||
.data(&(cpu.1)),
|
||||
|
@ -265,7 +265,6 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, c
|
|||
// Unwrap should be safe here, this assumes that the cpu_data vector is populated...
|
||||
dataset_vector.push(
|
||||
Dataset::default()
|
||||
//.name(&cpu_data.first().unwrap().0)
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.style(Style::default().fg(COLOUR_LIST[(cpu_data.len() - 1) % COLOUR_LIST.len()]))
|
||||
.data(&(cpu_data.first().unwrap().1)),
|
||||
|
@ -275,10 +274,10 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, c
|
|||
Chart::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.title("CPU Usage")
|
||||
.title("CPU")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::CPU => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
app::ApplicationPosition::Cpu => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
|
@ -288,9 +287,29 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, c
|
|||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_cpu_legend() {}
|
||||
fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, cpu_data: &[(String, Vec<(f64, f64)>)], draw_loc: Rect) {
|
||||
let mut itx = 0;
|
||||
let label_map = cpu_data.iter().map(|cpu| {
|
||||
itx += 1;
|
||||
Text::styled(&cpu.0, Style::default().fg(COLOUR_LIST[(itx - 1) % COLOUR_LIST.len()]))
|
||||
});
|
||||
|
||||
fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, swap_data: &[(f64, f64)], mem_data: &[(f64, f64)], draw_loc: Rect) {
|
||||
List::new(label_map)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::Cpu => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
.start_corner(Corner::TopLeft)
|
||||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_memory_graph<B: backend::Backend>(
|
||||
f: &mut Frame<B>, app_state: &app::App, memory_labels: &[(u64, u64)], mem_data: &[(f64, f64)], swap_data: &[(f64, f64)], draw_loc: Rect,
|
||||
) {
|
||||
let x_axis: Axis<String> = Axis::default()
|
||||
.style(Style::default().fg(GRAPH_COLOUR))
|
||||
.bounds([0.0, constants::TIME_STARTS_FROM as f64 * 10.0]);
|
||||
|
@ -299,8 +318,17 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App
|
|||
.bounds([-0.5, 100.5]) // Offset as the zero value isn't drawn otherwise...
|
||||
.labels(&["0%", "100%"]);
|
||||
|
||||
let mem_name = "RAM:".to_string()
|
||||
+ &format!("{:3}%", (mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
|
||||
+ &format!(
|
||||
" {:.1}GB/{:.1}GB",
|
||||
memory_labels.first().unwrap_or(&(0, 0)).0 as f64 / 1024.0,
|
||||
memory_labels.first().unwrap_or(&(0, 0)).1 as f64 / 1024.0
|
||||
);
|
||||
let swap_name: String;
|
||||
|
||||
let mut mem_canvas_vec: Vec<Dataset> = vec![Dataset::default()
|
||||
//.name(&mem_name)
|
||||
.name(&mem_name)
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.style(Style::default().fg(COLOUR_LIST[0]))
|
||||
.data(&mem_data)];
|
||||
|
@ -308,9 +336,16 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App
|
|||
if !(&swap_data).is_empty() {
|
||||
if let Some(last_canvas_result) = (&swap_data).last() {
|
||||
if last_canvas_result.1 >= 0.0 {
|
||||
swap_name = "SWP:".to_string()
|
||||
+ &format!("{:3}%", (swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))
|
||||
+ &format!(
|
||||
" {:.1}GB/{:.1}GB",
|
||||
memory_labels[1].0 as f64 / 1024.0,
|
||||
memory_labels[1].1 as f64 / 1024.0
|
||||
);
|
||||
mem_canvas_vec.push(
|
||||
Dataset::default()
|
||||
//.name(&swap_name)
|
||||
.name(&swap_name)
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.style(Style::default().fg(COLOUR_LIST[1]))
|
||||
.data(&swap_data),
|
||||
|
@ -322,10 +357,10 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App
|
|||
Chart::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.title("Memory Usage")
|
||||
.title("Memory")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::MEM => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
app::ApplicationPosition::Mem => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
|
@ -335,10 +370,9 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App
|
|||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_memory_legend() {}
|
||||
|
||||
fn draw_network_graph<B: backend::Backend>(
|
||||
f: &mut Frame<B>, app_state: &app::App, network_data_rx: &[(f64, f64)], network_data_tx: &[(f64, f64)], draw_loc: Rect,
|
||||
f: &mut Frame<B>, app_state: &app::App, network_data_rx: &[(f64, f64)], network_data_tx: &[(f64, f64)], rx_display: String, tx_display: String,
|
||||
draw_loc: Rect,
|
||||
) {
|
||||
let x_axis: Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
|
||||
let y_axis = Axis::default()
|
||||
|
@ -351,7 +385,7 @@ fn draw_network_graph<B: backend::Backend>(
|
|||
.title("Network")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::NETWORK => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
app::ApplicationPosition::Network => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
|
@ -359,10 +393,12 @@ fn draw_network_graph<B: backend::Backend>(
|
|||
.y_axis(y_axis)
|
||||
.datasets(&[
|
||||
Dataset::default()
|
||||
.name(&(rx_display))
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.style(Style::default().fg(COLOUR_LIST[0]))
|
||||
.data(&network_data_rx),
|
||||
Dataset::default()
|
||||
.name(&(tx_display))
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.style(Style::default().fg(COLOUR_LIST[1]))
|
||||
.data(&network_data_tx),
|
||||
|
@ -370,7 +406,26 @@ fn draw_network_graph<B: backend::Backend>(
|
|||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_network_legend() {}
|
||||
fn draw_network_labels<B: backend::Backend>(
|
||||
f: &mut Frame<B>, app_state: &mut app::App, total_rx_display: String, total_tx_display: String, draw_loc: Rect,
|
||||
) {
|
||||
// Gross but I need it to work...
|
||||
let total_network = vec![vec![total_rx_display, total_tx_display]];
|
||||
let mapped_network = total_network.iter().map(|val| Row::Data(val.iter()));
|
||||
|
||||
Table::new(["Total RX", "Total TX"].iter(), mapped_network)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::Temp => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
.header_style(Style::default().fg(Color::LightBlue))
|
||||
.widths(&[Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, temp_sensor_data: &[Vec<String>], draw_loc: Rect) {
|
||||
let num_rows = i64::from(draw_loc.height) - 4;
|
||||
|
@ -406,7 +461,7 @@ fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
|
|||
.title("Temperatures")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::TEMP => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
app::ApplicationPosition::Temp => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
|
@ -447,10 +502,10 @@ fn draw_disk_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
|
|||
Table::new(["Disk", "Mount", "Used", "Total", "Free", "R/s", "W/s"].iter(), disk_rows)
|
||||
.block(
|
||||
Block::default()
|
||||
.title("Disk Usage")
|
||||
.title("Disk")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::DISK => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
app::ApplicationPosition::Disk => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
|
@ -528,7 +583,7 @@ fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut a
|
|||
.title("Processes")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::PROCESS => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
app::ApplicationPosition::Process => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
|
@ -558,6 +613,11 @@ fn get_start_position(
|
|||
}
|
||||
}
|
||||
app::ScrollDirection::UP => {
|
||||
if *currently_selected_position == 0 {
|
||||
*previous_position = 0;
|
||||
return *previous_position;
|
||||
}
|
||||
|
||||
if *currently_selected_position == *previous_position - 1 {
|
||||
*previous_position = if *previous_position > 0 { *previous_position - 1 } else { 0 };
|
||||
*previous_position
|
||||
|
|
|
@ -44,8 +44,8 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec<Vec<String>> {
|
|||
let prev = &prev_io_hashmap[trimmed_mount];
|
||||
let read_bytes_per_sec = ((ele.read_bytes - prev.read_bytes) as f64 / time_difference) as u64;
|
||||
let write_bytes_per_sec = ((ele.write_bytes - prev.write_bytes) as f64 / time_difference) as u64;
|
||||
let converted_read = get_simple_byte_values(read_bytes_per_sec);
|
||||
let converted_write = get_simple_byte_values(write_bytes_per_sec);
|
||||
let converted_read = get_simple_byte_values(read_bytes_per_sec, false);
|
||||
let converted_write = get_simple_byte_values(write_bytes_per_sec, false);
|
||||
(
|
||||
format!("{:.*}{}/s", 0, converted_read.0, converted_read.1),
|
||||
format!("{:.*}{}/s", 0, converted_write.0, converted_write.1),
|
||||
|
@ -63,8 +63,8 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec<Vec<String>> {
|
|||
("0B/s".to_string(), "0B/s".to_string())
|
||||
};
|
||||
|
||||
let converted_free_space = get_simple_byte_values(disk.free_space);
|
||||
let converted_total_space = get_simple_byte_values(disk.total_space);
|
||||
let converted_free_space = get_simple_byte_values(disk.free_space, false);
|
||||
let converted_total_space = get_simple_byte_values(disk.total_space, false);
|
||||
disk_vector.push(vec![
|
||||
disk.name.to_string(),
|
||||
disk.mount_point.to_string(),
|
||||
|
@ -283,24 +283,24 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
|
|||
let tx_converted_result: (f64, String);
|
||||
|
||||
if let Some(last_num_bytes_entry) = network_data.last() {
|
||||
rx_converted_result = get_exact_byte_values(last_num_bytes_entry.rx);
|
||||
total_rx_converted_result = get_exact_byte_values(last_num_bytes_entry.total_rx);
|
||||
rx_converted_result = get_exact_byte_values(last_num_bytes_entry.rx, true);
|
||||
total_rx_converted_result = get_exact_byte_values(last_num_bytes_entry.total_rx, truefalse
|
||||
} else {
|
||||
rx_converted_result = get_exact_byte_values(0);
|
||||
total_rx_converted_result = get_exact_byte_values(0);
|
||||
rx_converted_result = get_exact_byte_values(0, true);
|
||||
total_rx_converted_result = get_exact_byte_values(0, false);
|
||||
}
|
||||
let rx_display = format!("RX: {:5.*}{}", 1, rx_converted_result.0, rx_converted_result.1);
|
||||
let total_rx_display = format!("Total RX: {:5.*}{}", 1, total_rx_converted_result.0, total_rx_converted_result.1);
|
||||
let total_rx_display = format!("{:.*}{}", 1, total_rx_converted_result.0, total_rx_converted_result.1);
|
||||
|
||||
if let Some(last_num_bytes_entry) = network_data.last() {
|
||||
tx_converted_result = get_exact_byte_values(last_num_bytes_entry.tx);
|
||||
total_tx_converted_result = get_exact_byte_values(last_num_bytes_entry.total_tx);
|
||||
tx_converted_result = get_exact_byte_values(last_num_bytes_entry.tx, true);
|
||||
total_tx_converted_result = get_exact_byte_values(last_num_bytes_entry.total_tx, false);
|
||||
} else {
|
||||
tx_converted_result = get_exact_byte_values(0);
|
||||
total_tx_converted_result = get_exact_byte_values(0);
|
||||
tx_converted_result = get_exact_byte_values(0, true);
|
||||
total_tx_converted_result = get_exact_byte_values(0, false);
|
||||
}
|
||||
let tx_display = format!("TX: {:5.*}{}", 1, tx_converted_result.0, tx_converted_result.1);
|
||||
let total_tx_display = format!("Total TX: {:5.*}{}", 1, total_tx_converted_result.0, total_tx_converted_result.1);
|
||||
let total_tx_display = format!("{:.*}{}", 1, total_tx_converted_result.0, total_tx_converted_result.1);
|
||||
|
||||
ConvertedNetworkData {
|
||||
rx,
|
||||
|
|
|
@ -24,9 +24,9 @@ pub fn float_max(a: f32, b: f32) -> f32 {
|
|||
|
||||
/// Returns a tuple containing the value and the unit. In units of 1024.
|
||||
/// This only supports up to a tebibyte.
|
||||
pub fn get_exact_byte_values(bytes: u64) -> (f64, String) {
|
||||
pub fn get_exact_byte_values(bytes: u64, spacing: bool) -> (f64, String) {
|
||||
match bytes {
|
||||
b if b < 1024 => (bytes as f64, "B".to_string()),
|
||||
b if b < 1024 => (bytes as f64, if spacing { " B".to_string() } else { "B".to_string() }),
|
||||
b if b < 1_048_576 => (bytes as f64 / 1024.0, "KiB".to_string()),
|
||||
b if b < 1_073_741_824 => (bytes as f64 / 1_048_576.0, "MiB".to_string()),
|
||||
b if b < 1_099_511_627_776 => (bytes as f64 / 1_073_741_824.0, "GiB".to_string()),
|
||||
|
@ -36,9 +36,9 @@ pub fn get_exact_byte_values(bytes: u64) -> (f64, String) {
|
|||
|
||||
/// Returns a tuple containing the value and the unit. In units of 1000.
|
||||
/// This only supports up to a terabyte. Note the "byte" unit will have a space appended to match the others.
|
||||
pub fn get_simple_byte_values(bytes: u64) -> (f64, String) {
|
||||
pub fn get_simple_byte_values(bytes: u64, spacing: bool) -> (f64, String) {
|
||||
match bytes {
|
||||
b if b < 1000 => (bytes as f64, "B".to_string()),
|
||||
b if b < 1000 => (bytes as f64, if spacing { " B".to_string() } else { "B".to_string() }),
|
||||
b if b < 1_000_000 => (bytes as f64 / 1000.0, "KB".to_string()),
|
||||
b if b < 1_000_000_000 => (bytes as f64 / 1_000_000.0, "MB".to_string()),
|
||||
b if b < 1_000_000_000_000 => (bytes as f64 / 1_000_000_000.0, "GB".to_string()),
|
||||
|
|
Loading…
Add table
Reference in a new issue