CPU specific line filtering added.
This commit is contained in:
parent
74df90010d
commit
8a718080a5
19
src/app.rs
19
src/app.rs
|
@ -363,6 +363,24 @@ impl App {
|
||||||
self.enable_grouping
|
self.enable_grouping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn on_space(&mut self) {
|
||||||
|
match self.current_widget_selected {
|
||||||
|
WidgetPosition::Cpu => {
|
||||||
|
let curr_posn = self
|
||||||
|
.app_scroll_positions
|
||||||
|
.cpu_scroll_state
|
||||||
|
.current_scroll_position;
|
||||||
|
if self.cpu_state.is_showing_tray
|
||||||
|
&& curr_posn < self.data_collection.cpu_harvest.len() as u64
|
||||||
|
{
|
||||||
|
self.cpu_state.core_show_vec[curr_posn as usize] =
|
||||||
|
!self.cpu_state.core_show_vec[curr_posn as usize];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn on_slash(&mut self) {
|
pub fn on_slash(&mut self) {
|
||||||
if !self.is_in_dialog() {
|
if !self.is_in_dialog() {
|
||||||
match self.current_widget_selected {
|
match self.current_widget_selected {
|
||||||
|
@ -808,6 +826,7 @@ impl App {
|
||||||
'L' => self.move_widget_selection_right(),
|
'L' => self.move_widget_selection_right(),
|
||||||
'K' => self.move_widget_selection_up(),
|
'K' => self.move_widget_selection_up(),
|
||||||
'J' => self.move_widget_selection_down(),
|
'J' => self.move_widget_selection_down(),
|
||||||
|
' ' => self.on_space(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
116
src/canvas.rs
116
src/canvas.rs
|
@ -23,9 +23,10 @@ use drawing_utils::*;
|
||||||
|
|
||||||
// Headers
|
// Headers
|
||||||
const CPU_LEGEND_HEADER: [&str; 2] = ["CPU", "Use%"];
|
const CPU_LEGEND_HEADER: [&str; 2] = ["CPU", "Use%"];
|
||||||
|
const CPU_SELECT_LEGEND_HEADER: [&str; 3] = ["CPU", "Use%", "Show"];
|
||||||
const DISK_HEADERS: [&str; 7] = ["Disk", "Mount", "Used", "Free", "Total", "R/s", "W/s"];
|
const DISK_HEADERS: [&str; 7] = ["Disk", "Mount", "Used", "Free", "Total", "R/s", "W/s"];
|
||||||
const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"];
|
const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"];
|
||||||
const MEM_HEADERS: [&str; 3] = ["Mem", "Usage", "Usage%"];
|
const MEM_HEADERS: [&str; 3] = ["Mem", "Usage", "Use%"];
|
||||||
const NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];
|
const NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];
|
||||||
const FORCE_MIN_THRESHOLD: usize = 5;
|
const FORCE_MIN_THRESHOLD: usize = 5;
|
||||||
|
|
||||||
|
@ -40,6 +41,10 @@ lazy_static! {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
static ref CPU_SELECT_LEGEND_HEADER_LENS: Vec<usize> = CPU_SELECT_LEGEND_HEADER
|
||||||
|
.iter()
|
||||||
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
||||||
|
.collect::<Vec<_>>();
|
||||||
static ref TEMP_HEADERS_LENS: Vec<usize> = TEMP_HEADERS
|
static ref TEMP_HEADERS_LENS: Vec<usize> = TEMP_HEADERS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
||||||
|
@ -532,22 +537,11 @@ impl Painter {
|
||||||
let mut dataset_vector: Vec<Dataset> = Vec::new();
|
let mut dataset_vector: Vec<Dataset> = Vec::new();
|
||||||
let mut cpu_entries_vec: Vec<(Style, Vec<(f64, f64)>)> = Vec::new();
|
let mut cpu_entries_vec: Vec<(Style, Vec<(f64, f64)>)> = Vec::new();
|
||||||
|
|
||||||
for (i, cpu) in cpu_data.iter().enumerate() {
|
for (itx, cpu) in cpu_data.iter().enumerate() {
|
||||||
cpu_entries_vec.push((
|
if app_state.cpu_state.core_show_vec[itx] {
|
||||||
self.colours.cpu_colour_styles[(i) % self.colours.cpu_colour_styles.len()],
|
|
||||||
cpu.cpu_data
|
|
||||||
.iter()
|
|
||||||
.map(<(f64, f64)>::from)
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if app_state.app_config_fields.show_average_cpu {
|
|
||||||
if let Some(avg_cpu_entry) = cpu_data.first() {
|
|
||||||
cpu_entries_vec.push((
|
cpu_entries_vec.push((
|
||||||
self.colours.cpu_colour_styles[0],
|
self.colours.cpu_colour_styles[(itx) % self.colours.cpu_colour_styles.len()],
|
||||||
avg_cpu_entry
|
cpu.cpu_data
|
||||||
.cpu_data
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(<(f64, f64)>::from)
|
.map(<(f64, f64)>::from)
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
|
@ -625,17 +619,27 @@ impl Painter {
|
||||||
let sliced_cpu_data = &cpu_data[start_position as usize..];
|
let sliced_cpu_data = &cpu_data[start_position as usize..];
|
||||||
let mut stringified_cpu_data: Vec<Vec<String>> = Vec::new();
|
let mut stringified_cpu_data: Vec<Vec<String>> = Vec::new();
|
||||||
|
|
||||||
for cpu in sliced_cpu_data {
|
for (itx, cpu) in sliced_cpu_data.iter().enumerate() {
|
||||||
if let Some(cpu_data) = cpu.cpu_data.last() {
|
if let Some(cpu_data) = cpu.cpu_data.last() {
|
||||||
stringified_cpu_data.push(vec![
|
let mut entry = vec![
|
||||||
cpu.cpu_name.clone(),
|
cpu.cpu_name.clone(),
|
||||||
format!("{:.0}%", cpu_data.usage.round()),
|
format!("{:.0}%", cpu_data.usage.round()),
|
||||||
]);
|
];
|
||||||
|
|
||||||
|
if app_state.cpu_state.is_showing_tray {
|
||||||
|
entry.push(
|
||||||
|
if app_state.cpu_state.core_show_vec[itx + start_position as usize] {
|
||||||
|
"*".to_string()
|
||||||
|
} else {
|
||||||
|
String::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
stringified_cpu_data.push(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cpu_row_counter: i64 = 0;
|
|
||||||
|
|
||||||
let cpu_rows = stringified_cpu_data
|
let cpu_rows = stringified_cpu_data
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
@ -644,25 +648,22 @@ impl Painter {
|
||||||
cpu_string_row.iter(),
|
cpu_string_row.iter(),
|
||||||
match app_state.current_widget_selected {
|
match app_state.current_widget_selected {
|
||||||
app::WidgetPosition::Cpu => {
|
app::WidgetPosition::Cpu => {
|
||||||
if cpu_row_counter as u64
|
if itx as u64
|
||||||
== app_state
|
== app_state
|
||||||
.app_scroll_positions
|
.app_scroll_positions
|
||||||
.cpu_scroll_state
|
.cpu_scroll_state
|
||||||
.current_scroll_position - start_position
|
.current_scroll_position - start_position
|
||||||
{
|
{
|
||||||
cpu_row_counter = -1;
|
|
||||||
self.colours.currently_selected_text_style
|
self.colours.currently_selected_text_style
|
||||||
} else {
|
} else {
|
||||||
if cpu_row_counter >= 0 {
|
self.colours.cpu_colour_styles[itx
|
||||||
cpu_row_counter += 1;
|
+ start_position as usize
|
||||||
}
|
% self.colours.cpu_colour_styles.len()]
|
||||||
self.colours.cpu_colour_styles
|
|
||||||
[itx % self.colours.cpu_colour_styles.len()]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.colours.cpu_colour_styles
|
self.colours.cpu_colour_styles[itx
|
||||||
[itx % self.colours.cpu_colour_styles.len()]
|
+ start_position as usize % self.colours.cpu_colour_styles.len()]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -670,27 +671,46 @@ impl Painter {
|
||||||
|
|
||||||
// Calculate widths
|
// Calculate widths
|
||||||
let width = f64::from(draw_loc.width);
|
let width = f64::from(draw_loc.width);
|
||||||
let width_ratios = vec![0.5, 0.5];
|
let width_ratios = if app_state.cpu_state.is_showing_tray {
|
||||||
let variable_intrinsic_results =
|
vec![0.4, 0.3, 0.3]
|
||||||
get_variable_intrinsic_widths(width as u16, &width_ratios, &CPU_LEGEND_HEADER_LENS);
|
} else {
|
||||||
|
vec![0.5, 0.5]
|
||||||
|
};
|
||||||
|
let variable_intrinsic_results = get_variable_intrinsic_widths(
|
||||||
|
width as u16,
|
||||||
|
&width_ratios,
|
||||||
|
if app_state.cpu_state.is_showing_tray {
|
||||||
|
&CPU_SELECT_LEGEND_HEADER_LENS
|
||||||
|
} else {
|
||||||
|
&CPU_LEGEND_HEADER_LENS
|
||||||
|
},
|
||||||
|
);
|
||||||
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
Table::new(CPU_LEGEND_HEADER.iter(), cpu_rows)
|
Table::new(
|
||||||
.block(Block::default().borders(Borders::ALL).border_style(
|
if app_state.cpu_state.is_showing_tray {
|
||||||
match app_state.current_widget_selected {
|
CPU_SELECT_LEGEND_HEADER.to_vec()
|
||||||
app::WidgetPosition::Cpu => self.colours.highlighted_border_style,
|
} else {
|
||||||
_ => self.colours.border_style,
|
CPU_LEGEND_HEADER.to_vec()
|
||||||
},
|
}
|
||||||
))
|
.iter(),
|
||||||
.header_style(self.colours.table_header_style)
|
cpu_rows,
|
||||||
.widths(
|
)
|
||||||
&(intrinsic_widths
|
.block(Block::default().borders(Borders::ALL).border_style(
|
||||||
.iter()
|
match app_state.current_widget_selected {
|
||||||
.map(|calculated_width| Constraint::Length(*calculated_width as u16))
|
app::WidgetPosition::Cpu => self.colours.highlighted_border_style,
|
||||||
.collect::<Vec<_>>()),
|
_ => self.colours.border_style,
|
||||||
)
|
},
|
||||||
.render(f, draw_loc);
|
))
|
||||||
|
.header_style(self.colours.table_header_style)
|
||||||
|
.widths(
|
||||||
|
&(intrinsic_widths
|
||||||
|
.iter()
|
||||||
|
.map(|calculated_width| Constraint::Length(*calculated_width as u16))
|
||||||
|
.collect::<Vec<_>>()),
|
||||||
|
)
|
||||||
|
.render(f, draw_loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_memory_graph<B: backend::Backend>(
|
fn draw_memory_graph<B: backend::Backend>(
|
||||||
|
|
|
@ -37,11 +37,10 @@ pub fn gen_n_styles(num_to_gen: i32) -> Vec<Style> {
|
||||||
Style::default().fg(Color::LightMagenta),
|
Style::default().fg(Color::LightMagenta),
|
||||||
Style::default().fg(Color::LightCyan),
|
Style::default().fg(Color::LightCyan),
|
||||||
Style::default().fg(Color::Green),
|
Style::default().fg(Color::Green),
|
||||||
Style::default().fg(Color::Red),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut h: f32 = 0.4; // We don't need random colours... right?
|
let mut h: f32 = 0.4; // We don't need random colours... right?
|
||||||
for _i in 0..(num_to_gen - 6) {
|
for _i in 0..(num_to_gen - 5) {
|
||||||
h = gen_hsv(h);
|
h = gen_hsv(h);
|
||||||
let result = hsv_to_rgb(h, 0.5, 0.95);
|
let result = hsv_to_rgb(h, 0.5, 0.95);
|
||||||
colour_vec.push(Style::default().fg(Color::Rgb(result.0, result.1, result.2)));
|
colour_vec.push(Style::default().fg(Color::Rgb(result.0, result.1, result.2)));
|
||||||
|
|
|
@ -254,6 +254,13 @@ fn main() -> error::Result<()> {
|
||||||
&app.data_collection,
|
&app.data_collection,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Pre-fill CPU if needed
|
||||||
|
for itx in 0..app.canvas_data.cpu_data.len() {
|
||||||
|
if app.cpu_state.core_show_vec.len() <= itx {
|
||||||
|
app.cpu_state.core_show_vec.push(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Processes
|
// Processes
|
||||||
let (single, grouped) = convert_process_data(&app.data_collection);
|
let (single, grouped) = convert_process_data(&app.data_collection);
|
||||||
app.canvas_data.process_data = single;
|
app.canvas_data.process_data = single;
|
||||||
|
|
Loading…
Reference in New Issue