2020-01-05 00:20:54 +00:00
|
|
|
use crate::{
|
2020-02-12 02:16:43 +00:00
|
|
|
app::{self, data_harvester::processes::ProcessHarvest, WidgetPosition},
|
2020-02-08 19:28:19 +00:00
|
|
|
constants::*,
|
2020-02-02 04:49:44 +00:00
|
|
|
data_conversion::{ConvertedCpuData, ConvertedProcessData},
|
2020-02-08 23:00:50 +00:00
|
|
|
utils::error,
|
2020-01-05 00:20:54 +00:00
|
|
|
};
|
2020-01-11 22:30:04 +00:00
|
|
|
use std::cmp::max;
|
2020-02-02 04:49:44 +00:00
|
|
|
use std::collections::HashMap;
|
2019-12-06 05:57:04 +00:00
|
|
|
use tui::{
|
2019-09-17 03:53:20 +00:00
|
|
|
backend,
|
2020-01-01 22:55:15 +00:00
|
|
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
2020-01-12 20:41:27 +00:00
|
|
|
style::{Color, Style},
|
2019-12-28 03:39:25 +00:00
|
|
|
terminal::Frame,
|
2020-01-01 22:55:15 +00:00
|
|
|
widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Paragraph, Row, Table, Text, Widget},
|
2019-09-11 03:37:20 +00:00
|
|
|
Terminal,
|
|
|
|
};
|
2019-09-12 02:10:49 +00:00
|
|
|
|
2020-02-08 23:00:50 +00:00
|
|
|
mod canvas_colours;
|
|
|
|
use canvas_colours::*;
|
2020-02-10 02:34:44 +00:00
|
|
|
|
|
|
|
mod drawing_utils;
|
|
|
|
use drawing_utils::*;
|
|
|
|
|
2020-01-11 22:30:04 +00:00
|
|
|
// Headers
|
|
|
|
const CPU_LEGEND_HEADER: [&str; 2] = ["CPU", "Use%"];
|
2020-02-18 00:25:59 +00:00
|
|
|
const CPU_SELECT_LEGEND_HEADER: [&str; 2] = ["CPU", "Show (Space)"];
|
2020-01-11 22:30:04 +00:00
|
|
|
const DISK_HEADERS: [&str; 7] = ["Disk", "Mount", "Used", "Free", "Total", "R/s", "W/s"];
|
|
|
|
const TEMP_HEADERS: [&str; 2] = ["Sensor", "Temp"];
|
2020-02-16 22:48:24 +00:00
|
|
|
const MEM_HEADERS: [&str; 3] = ["Mem", "Usage", "Use%"];
|
2020-02-10 03:19:05 +00:00
|
|
|
const NETWORK_HEADERS: [&str; 4] = ["RX", "TX", "Total RX", "Total TX"];
|
2020-01-11 22:30:04 +00:00
|
|
|
const FORCE_MIN_THRESHOLD: usize = 5;
|
|
|
|
|
2019-12-27 00:06:30 +00:00
|
|
|
lazy_static! {
|
2020-02-09 03:38:55 +00:00
|
|
|
static ref DEFAULT_TEXT_STYLE: Style = Style::default().fg(Color::Gray);
|
|
|
|
static ref DEFAULT_HEADER_STYLE: Style = Style::default().fg(Color::LightBlue);
|
2020-01-11 22:30:04 +00:00
|
|
|
static ref DISK_HEADERS_LENS: Vec<usize> = DISK_HEADERS
|
|
|
|
.iter()
|
|
|
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
static ref CPU_LEGEND_HEADER_LENS: Vec<usize> = CPU_LEGEND_HEADER
|
|
|
|
.iter()
|
|
|
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
|
|
|
.collect::<Vec<_>>();
|
2020-02-16 22:48:24 +00:00
|
|
|
static ref CPU_SELECT_LEGEND_HEADER_LENS: Vec<usize> = CPU_SELECT_LEGEND_HEADER
|
|
|
|
.iter()
|
|
|
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
|
|
|
.collect::<Vec<_>>();
|
2020-01-11 22:30:04 +00:00
|
|
|
static ref TEMP_HEADERS_LENS: Vec<usize> = TEMP_HEADERS
|
|
|
|
.iter()
|
|
|
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
|
|
|
.collect::<Vec<_>>();
|
2020-01-14 03:06:44 +00:00
|
|
|
static ref MEM_HEADERS_LENS: Vec<usize> = MEM_HEADERS
|
|
|
|
.iter()
|
|
|
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
|
|
|
.collect::<Vec<_>>();
|
2020-02-10 03:19:05 +00:00
|
|
|
static ref NETWORK_HEADERS_LENS: Vec<usize> = NETWORK_HEADERS
|
2020-01-11 22:30:04 +00:00
|
|
|
.iter()
|
|
|
|
.map(|entry| max(FORCE_MIN_THRESHOLD, entry.len()))
|
|
|
|
.collect::<Vec<_>>();
|
2019-12-27 00:06:30 +00:00
|
|
|
}
|
2019-09-12 02:10:49 +00:00
|
|
|
|
|
|
|
#[derive(Default)]
|
2020-02-02 04:49:44 +00:00
|
|
|
pub struct DisplayableData {
|
2019-12-06 05:57:04 +00:00
|
|
|
pub rx_display: String,
|
|
|
|
pub tx_display: String,
|
2019-12-27 23:30:35 +00:00
|
|
|
pub total_rx_display: String,
|
|
|
|
pub total_tx_display: String,
|
2019-12-06 05:57:04 +00:00
|
|
|
pub network_data_rx: Vec<(f64, f64)>,
|
|
|
|
pub network_data_tx: Vec<(f64, f64)>,
|
|
|
|
pub disk_data: Vec<Vec<String>>,
|
|
|
|
pub temp_sensor_data: Vec<Vec<String>>,
|
2020-02-08 19:28:19 +00:00
|
|
|
pub process_data: HashMap<u32, ProcessHarvest>, // Not the final value
|
|
|
|
pub grouped_process_data: Vec<ConvertedProcessData>, // Not the final value
|
2020-02-02 04:49:44 +00:00
|
|
|
pub finalized_process_data: Vec<ConvertedProcessData>, // What's actually displayed
|
2020-01-26 21:44:24 +00:00
|
|
|
pub mem_label: String,
|
|
|
|
pub swap_label: String,
|
2019-12-06 05:57:04 +00:00
|
|
|
pub mem_data: Vec<(f64, f64)>,
|
|
|
|
pub swap_data: Vec<(f64, f64)>,
|
2020-01-05 00:20:54 +00:00
|
|
|
pub cpu_data: Vec<ConvertedCpuData>,
|
2019-09-12 02:10:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 04:21:44 +00:00
|
|
|
#[allow(dead_code)]
|
2020-02-05 03:44:49 +00:00
|
|
|
#[derive(Default)]
|
2020-02-08 19:28:19 +00:00
|
|
|
/// Handles the canvas' state. TODO: [OPT] implement this.
|
2020-02-05 04:21:44 +00:00
|
|
|
pub struct Painter {
|
|
|
|
height: f64,
|
|
|
|
width: f64,
|
|
|
|
vertical_dialog_chunk: Vec<Rect>,
|
|
|
|
middle_dialog_chunk: Vec<Rect>,
|
|
|
|
vertical_chunks: Vec<Rect>,
|
|
|
|
middle_chunks: Vec<Rect>,
|
|
|
|
middle_divided_chunk_2: Vec<Rect>,
|
|
|
|
bottom_chunks: Vec<Rect>,
|
|
|
|
cpu_chunk: Vec<Rect>,
|
|
|
|
network_chunk: Vec<Rect>,
|
2020-02-08 19:28:19 +00:00
|
|
|
pub colours: CanvasColours,
|
2020-02-10 02:27:02 +00:00
|
|
|
pub styled_general_help_text: Vec<Text<'static>>,
|
|
|
|
pub styled_process_help_text: Vec<Text<'static>>,
|
|
|
|
pub styled_search_help_text: Vec<Text<'static>>,
|
2020-02-08 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
impl Painter {
|
2020-02-10 02:27:02 +00:00
|
|
|
/// Must be run once before drawing, but after setting colours.
|
|
|
|
/// This is to set some remaining styles and text.
|
|
|
|
/// This bypasses some logic checks (size > 2, for example) but this
|
|
|
|
/// assumes that you, the programmer, are sane and do not do stupid things.
|
2020-02-16 23:40:13 +00:00
|
|
|
/// RIGHT?
|
2020-02-10 02:27:02 +00:00
|
|
|
pub fn initialize(&mut self) {
|
|
|
|
self.styled_general_help_text.push(Text::Styled(
|
|
|
|
GENERAL_HELP_TEXT[0].into(),
|
|
|
|
self.colours.table_header_style,
|
|
|
|
));
|
|
|
|
self.styled_general_help_text.extend(
|
|
|
|
GENERAL_HELP_TEXT[1..]
|
|
|
|
.iter()
|
|
|
|
.map(|&text| Text::Styled(text.into(), self.colours.text_style))
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
);
|
|
|
|
|
|
|
|
self.styled_process_help_text.push(Text::Styled(
|
|
|
|
PROCESS_HELP_TEXT[0].into(),
|
|
|
|
self.colours.table_header_style,
|
|
|
|
));
|
|
|
|
self.styled_process_help_text.extend(
|
|
|
|
PROCESS_HELP_TEXT[1..]
|
|
|
|
.iter()
|
|
|
|
.map(|&text| Text::Styled(text.into(), self.colours.text_style))
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
);
|
|
|
|
|
|
|
|
self.styled_search_help_text.push(Text::Styled(
|
|
|
|
SEARCH_HELP_TEXT[0].into(),
|
|
|
|
self.colours.table_header_style,
|
|
|
|
));
|
|
|
|
self.styled_search_help_text.extend(
|
|
|
|
SEARCH_HELP_TEXT[1..]
|
|
|
|
.iter()
|
|
|
|
.map(|&text| Text::Styled(text.into(), self.colours.text_style))
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-18 04:28:06 +00:00
|
|
|
// TODO: [REFACTOR] We should clean this up tbh
|
|
|
|
#[allow(clippy::cognitive_complexity)]
|
2020-02-05 03:44:49 +00:00
|
|
|
pub fn draw_data<B: backend::Backend>(
|
|
|
|
&mut self, terminal: &mut Terminal<B>, app_state: &mut app::App,
|
|
|
|
) -> error::Result<()> {
|
|
|
|
terminal.autoresize()?;
|
|
|
|
terminal.draw(|mut f| {
|
2020-02-09 22:11:57 +00:00
|
|
|
if app_state.help_dialog_state.is_showing_help {
|
2020-02-05 03:44:49 +00:00
|
|
|
// Only for the help
|
|
|
|
let vertical_dialog_chunk = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(1)
|
|
|
|
.constraints(
|
|
|
|
[
|
2020-02-18 04:28:06 +00:00
|
|
|
Constraint::Percentage(20),
|
|
|
|
Constraint::Percentage(60),
|
|
|
|
Constraint::Percentage(20),
|
2020-02-05 03:44:49 +00:00
|
|
|
]
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(f.size());
|
2020-01-02 04:39:47 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let middle_dialog_chunk = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
|
|
|
.constraints(
|
|
|
|
[
|
|
|
|
Constraint::Percentage(20),
|
|
|
|
Constraint::Percentage(60),
|
|
|
|
Constraint::Percentage(20),
|
|
|
|
]
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(vertical_dialog_chunk[1]);
|
2020-01-02 04:39:47 +00:00
|
|
|
|
2020-02-10 02:27:02 +00:00
|
|
|
const HELP_BASE: &str =
|
|
|
|
" Help ── 1: General ─── 2: Processes ─── 3: Search ─── Esc to close ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
middle_dialog_chunk[1].width as i32 - HELP_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let help_title = format!(
|
|
|
|
" Help ─{}─ 1: General ─── 2: Processes ─── 3: Search ─── Esc to close ",
|
|
|
|
"─".repeat(repeat_num as usize)
|
|
|
|
);
|
|
|
|
|
|
|
|
Paragraph::new(
|
|
|
|
match app_state.help_dialog_state.current_category {
|
|
|
|
app::AppHelpCategory::General => &self.styled_general_help_text,
|
|
|
|
app::AppHelpCategory::Process => &self.styled_process_help_text,
|
|
|
|
app::AppHelpCategory::Search => &self.styled_search_help_text,
|
|
|
|
}
|
|
|
|
.iter(),
|
|
|
|
)
|
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title(&help_title)
|
|
|
|
.title_style(self.colours.border_style)
|
|
|
|
.style(self.colours.border_style)
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(self.colours.border_style),
|
|
|
|
)
|
|
|
|
.style(self.colours.text_style)
|
|
|
|
.alignment(Alignment::Left)
|
|
|
|
.wrap(true)
|
|
|
|
.render(&mut f, middle_dialog_chunk[1]);
|
2020-02-09 22:11:57 +00:00
|
|
|
} else if app_state.delete_dialog_state.is_showing_dd {
|
2020-02-05 03:44:49 +00:00
|
|
|
let vertical_dialog_chunk = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(1)
|
|
|
|
.constraints(
|
|
|
|
[
|
2020-02-18 04:28:06 +00:00
|
|
|
Constraint::Percentage(35),
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
Constraint::Percentage(35),
|
2020-02-05 03:44:49 +00:00
|
|
|
]
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(f.size());
|
|
|
|
|
|
|
|
let middle_dialog_chunk = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
|
|
|
.constraints(
|
|
|
|
[
|
2020-02-18 04:28:06 +00:00
|
|
|
Constraint::Percentage(25),
|
|
|
|
Constraint::Percentage(50),
|
|
|
|
Constraint::Percentage(25),
|
2020-02-05 03:44:49 +00:00
|
|
|
]
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(vertical_dialog_chunk[1]);
|
|
|
|
|
2020-02-17 22:53:49 +00:00
|
|
|
if let Some(dd_err) = &app_state.dd_err {
|
2020-02-05 03:44:49 +00:00
|
|
|
let dd_text = [Text::raw(format!(
|
|
|
|
"\nFailure to properly kill the process - {}",
|
|
|
|
dd_err
|
|
|
|
))];
|
2020-01-02 04:39:47 +00:00
|
|
|
|
2020-02-10 02:27:02 +00:00
|
|
|
const ERROR_BASE: &str = " Error ── Esc to close ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
middle_dialog_chunk[1].width as i32 - ERROR_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let error_title =
|
|
|
|
format!(" Error ─{}─ Esc to close ", "─".repeat(repeat_num as usize));
|
2020-02-10 00:16:30 +00:00
|
|
|
|
2020-01-09 03:36:36 +00:00
|
|
|
Paragraph::new(dd_text.iter())
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-10 00:16:30 +00:00
|
|
|
.title(&error_title)
|
2020-02-10 02:27:02 +00:00
|
|
|
.title_style(self.colours.border_style)
|
2020-02-08 19:28:19 +00:00
|
|
|
.style(self.colours.border_style)
|
2020-02-10 02:27:02 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(self.colours.border_style),
|
2020-01-09 03:36:36 +00:00
|
|
|
)
|
2020-02-08 21:39:50 +00:00
|
|
|
.style(self.colours.text_style)
|
2020-01-09 03:36:36 +00:00
|
|
|
.alignment(Alignment::Center)
|
|
|
|
.wrap(true)
|
|
|
|
.render(&mut f, middle_dialog_chunk[1]);
|
2020-02-05 03:44:49 +00:00
|
|
|
} else if let Some(to_kill_processes) = app_state.get_to_delete_processes() {
|
|
|
|
if let Some(first_pid) = to_kill_processes.1.first() {
|
2020-02-18 04:28:06 +00:00
|
|
|
let dd_text = vec![
|
2020-02-05 03:44:49 +00:00
|
|
|
if app_state.is_grouped() {
|
2020-02-09 22:11:57 +00:00
|
|
|
if to_kill_processes.1.len() != 1 {
|
|
|
|
Text::raw(format!(
|
|
|
|
"\nAre you sure you want to kill {} processes with the name {}?",
|
|
|
|
to_kill_processes.1.len(), to_kill_processes.0
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
Text::raw(format!(
|
|
|
|
"\nAre you sure you want to kill {} process with the name {}?",
|
|
|
|
to_kill_processes.1.len(), to_kill_processes.0
|
|
|
|
))
|
|
|
|
}
|
2020-02-05 03:44:49 +00:00
|
|
|
} else {
|
|
|
|
Text::raw(format!(
|
|
|
|
"\nAre you sure you want to kill process {} with PID {}?",
|
|
|
|
to_kill_processes.0, first_pid
|
|
|
|
))
|
|
|
|
},
|
2020-02-10 00:16:30 +00:00
|
|
|
Text::raw("\nNote that if bottom is frozen, it must be unfrozen for changes to be shown.\n\n\n"),
|
2020-02-09 22:11:57 +00:00
|
|
|
if app_state.delete_dialog_state.is_on_yes {
|
|
|
|
Text::styled("Yes", self.colours.currently_selected_text_style)
|
|
|
|
} else {
|
|
|
|
Text::raw("Yes")
|
|
|
|
},
|
|
|
|
Text::raw(" "),
|
|
|
|
if app_state.delete_dialog_state.is_on_yes {
|
|
|
|
Text::raw("No")
|
|
|
|
} else {
|
|
|
|
Text::styled("No", self.colours.currently_selected_text_style)
|
|
|
|
},
|
2020-02-05 03:44:49 +00:00
|
|
|
];
|
|
|
|
|
2020-02-10 02:27:02 +00:00
|
|
|
const DD_BASE: &str = " Confirm Kill Process ── Esc to close ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
middle_dialog_chunk[1].width as i32
|
|
|
|
- DD_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let dd_title = format!(
|
|
|
|
" Confirm Kill Process ─{}─ Esc to close ",
|
|
|
|
"─".repeat(repeat_num as usize)
|
|
|
|
);
|
2020-02-10 00:16:30 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
Paragraph::new(dd_text.iter())
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-10 00:16:30 +00:00
|
|
|
.title(&dd_title)
|
2020-02-10 02:27:02 +00:00
|
|
|
.title_style(self.colours.border_style)
|
2020-02-08 19:28:19 +00:00
|
|
|
.style(self.colours.border_style)
|
2020-02-10 02:27:02 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(self.colours.border_style),
|
2020-02-05 03:44:49 +00:00
|
|
|
)
|
2020-02-08 21:39:50 +00:00
|
|
|
.style(self.colours.text_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.alignment(Alignment::Center)
|
|
|
|
.wrap(true)
|
|
|
|
.render(&mut f, middle_dialog_chunk[1]);
|
|
|
|
} else {
|
|
|
|
// This is a bit nasty, but it works well... I guess.
|
2020-02-09 22:11:57 +00:00
|
|
|
app_state.delete_dialog_state.is_showing_dd = false;
|
2020-02-05 03:44:49 +00:00
|
|
|
}
|
2020-01-09 03:36:36 +00:00
|
|
|
} else {
|
2020-02-02 05:52:41 +00:00
|
|
|
// This is a bit nasty, but it works well... I guess.
|
2020-02-09 22:11:57 +00:00
|
|
|
app_state.delete_dialog_state.is_showing_dd = false;
|
2020-01-09 03:36:36 +00:00
|
|
|
}
|
2020-02-12 02:16:43 +00:00
|
|
|
} else if app_state.is_expanded {
|
|
|
|
// TODO: [REF] we should combine this with normal drawing tbh
|
|
|
|
|
|
|
|
let rect = Layout::default()
|
|
|
|
.margin(1)
|
|
|
|
.constraints([Constraint::Percentage(100)].as_ref())
|
|
|
|
.split(f.size());
|
|
|
|
match &app_state.current_widget_selected {
|
|
|
|
WidgetPosition::Cpu => {
|
|
|
|
let cpu_chunk = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
|
|
|
.constraints(
|
|
|
|
if app_state.app_config_fields.left_legend {
|
|
|
|
[Constraint::Percentage(15), Constraint::Percentage(85)]
|
|
|
|
} else {
|
|
|
|
[Constraint::Percentage(85), Constraint::Percentage(15)]
|
|
|
|
}
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(rect[0]);
|
|
|
|
|
|
|
|
let legend_index = if app_state.app_config_fields.left_legend {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
1
|
|
|
|
};
|
|
|
|
let graph_index = if app_state.app_config_fields.left_legend {
|
|
|
|
1
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
self.draw_cpu_graph(&mut f, &app_state, cpu_chunk[graph_index]);
|
|
|
|
self.draw_cpu_legend(&mut f, app_state, cpu_chunk[legend_index]);
|
|
|
|
}
|
|
|
|
WidgetPosition::Mem => {
|
|
|
|
self.draw_memory_graph(&mut f, &app_state, rect[0]);
|
|
|
|
}
|
|
|
|
WidgetPosition::Disk => {
|
|
|
|
self.draw_disk_table(&mut f, app_state, rect[0]);
|
|
|
|
}
|
|
|
|
WidgetPosition::Temp => {
|
|
|
|
self.draw_temp_table(&mut f, app_state, rect[0]);
|
|
|
|
}
|
|
|
|
WidgetPosition::Network => {
|
|
|
|
self.draw_network_graph(&mut f, &app_state, rect[0]);
|
|
|
|
}
|
|
|
|
WidgetPosition::Process | WidgetPosition::ProcessSearch => {
|
|
|
|
if app_state.is_searching() {
|
|
|
|
let processes_chunk = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(0)
|
|
|
|
.constraints(
|
|
|
|
[Constraint::Percentage(85), Constraint::Percentage(15)]
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(rect[0]);
|
|
|
|
|
|
|
|
self.draw_processes_table(&mut f, app_state, processes_chunk[0]);
|
|
|
|
self.draw_search_field(&mut f, app_state, processes_chunk[1]);
|
|
|
|
} else {
|
|
|
|
self.draw_processes_table(&mut f, app_state, rect[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-02 04:39:47 +00:00
|
|
|
} else {
|
2020-02-05 03:44:49 +00:00
|
|
|
// TODO: [TUI] Change this back to a more even 33/33/34 when TUI releases
|
|
|
|
let vertical_chunks = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(1)
|
|
|
|
.constraints(
|
|
|
|
[
|
|
|
|
Constraint::Percentage(30),
|
|
|
|
Constraint::Percentage(37),
|
|
|
|
Constraint::Percentage(33),
|
|
|
|
]
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(f.size());
|
2019-10-10 02:00:10 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let middle_chunks = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
|
|
|
.constraints([Constraint::Percentage(60), Constraint::Percentage(40)].as_ref())
|
|
|
|
.split(vertical_chunks[1]);
|
2019-10-10 02:00:10 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let middle_divided_chunk_2 = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(0)
|
|
|
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
|
|
|
.split(middle_chunks[1]);
|
2019-12-28 06:20:05 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let bottom_chunks = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
|
|
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
|
|
|
.split(vertical_chunks[2]);
|
2019-12-28 06:20:05 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Component specific chunks
|
|
|
|
let cpu_chunk = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.margin(0)
|
|
|
|
.constraints(
|
2020-02-12 02:16:43 +00:00
|
|
|
if app_state.app_config_fields.left_legend {
|
2020-02-05 03:44:49 +00:00
|
|
|
[Constraint::Percentage(15), Constraint::Percentage(85)]
|
|
|
|
} else {
|
|
|
|
[Constraint::Percentage(85), Constraint::Percentage(15)]
|
|
|
|
}
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(vertical_chunks[0]);
|
2019-10-10 02:00:10 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let network_chunk = Layout::default()
|
2020-01-12 19:25:47 +00:00
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(0)
|
2020-02-03 04:15:24 +00:00
|
|
|
.constraints(
|
2020-02-05 03:44:49 +00:00
|
|
|
if (bottom_chunks[0].height as f64 * 0.25) as u16 >= 4 {
|
2020-02-03 04:15:24 +00:00
|
|
|
[Constraint::Percentage(75), Constraint::Percentage(25)]
|
|
|
|
} else {
|
2020-02-05 03:44:49 +00:00
|
|
|
let required = if bottom_chunks[0].height < 10 {
|
|
|
|
bottom_chunks[0].height / 2
|
2020-02-03 04:15:24 +00:00
|
|
|
} else {
|
|
|
|
5
|
|
|
|
};
|
2020-02-05 03:44:49 +00:00
|
|
|
let remaining = bottom_chunks[0].height - required;
|
2020-02-03 04:15:24 +00:00
|
|
|
[Constraint::Length(remaining), Constraint::Length(required)]
|
|
|
|
}
|
|
|
|
.as_ref(),
|
|
|
|
)
|
2020-02-05 03:44:49 +00:00
|
|
|
.split(bottom_chunks[0]);
|
2020-02-03 04:15:24 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Default chunk index based on left or right legend setting
|
2020-02-12 02:16:43 +00:00
|
|
|
let legend_index = if app_state.app_config_fields.left_legend {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
1
|
|
|
|
};
|
|
|
|
let graph_index = if app_state.app_config_fields.left_legend {
|
|
|
|
1
|
|
|
|
} else {
|
|
|
|
0
|
|
|
|
};
|
2019-09-12 02:10:49 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Set up blocks and their components
|
2020-02-17 22:42:51 +00:00
|
|
|
// CPU graph + legend
|
2020-02-05 03:44:49 +00:00
|
|
|
self.draw_cpu_graph(&mut f, &app_state, cpu_chunk[graph_index]);
|
|
|
|
self.draw_cpu_legend(&mut f, app_state, cpu_chunk[legend_index]);
|
|
|
|
|
|
|
|
//Memory usage graph
|
|
|
|
self.draw_memory_graph(&mut f, &app_state, middle_chunks[0]);
|
|
|
|
|
|
|
|
// Network graph
|
|
|
|
self.draw_network_graph(&mut f, &app_state, network_chunk[0]);
|
|
|
|
self.draw_network_labels(&mut f, app_state, network_chunk[1]);
|
2019-09-25 20:43:13 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Temperature table
|
|
|
|
self.draw_temp_table(&mut f, app_state, middle_divided_chunk_2[0]);
|
|
|
|
|
|
|
|
// Disk usage table
|
|
|
|
self.draw_disk_table(&mut f, app_state, middle_divided_chunk_2[1]);
|
|
|
|
|
|
|
|
// Processes table
|
|
|
|
if app_state.is_searching() {
|
|
|
|
let processes_chunk = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.margin(0)
|
|
|
|
.constraints(
|
|
|
|
if (bottom_chunks[1].height as f64 * 0.25) as u16 >= 4 {
|
|
|
|
[Constraint::Percentage(75), Constraint::Percentage(25)]
|
|
|
|
} else {
|
|
|
|
let required = if bottom_chunks[1].height < 10 {
|
|
|
|
bottom_chunks[1].height / 2
|
|
|
|
} else {
|
|
|
|
5
|
|
|
|
};
|
|
|
|
let remaining = bottom_chunks[1].height - required;
|
|
|
|
[Constraint::Length(remaining), Constraint::Length(required)]
|
|
|
|
}
|
|
|
|
.as_ref(),
|
|
|
|
)
|
|
|
|
.split(bottom_chunks[1]);
|
|
|
|
|
|
|
|
self.draw_processes_table(&mut f, app_state, processes_chunk[0]);
|
|
|
|
self.draw_search_field(&mut f, app_state, processes_chunk[1]);
|
|
|
|
} else {
|
|
|
|
self.draw_processes_table(&mut f, app_state, bottom_chunks[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})?;
|
|
|
|
|
|
|
|
Ok(())
|
2020-01-05 00:20:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
fn draw_cpu_graph<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let cpu_data: &[ConvertedCpuData] = &app_state.canvas_data.cpu_data;
|
|
|
|
|
|
|
|
// CPU usage graph
|
2020-02-08 19:28:19 +00:00
|
|
|
let x_axis: Axis<String> = Axis::default().bounds([0.0, TIME_STARTS_FROM as f64]);
|
2020-02-05 03:44:49 +00:00
|
|
|
let y_axis = Axis::default()
|
2020-02-08 21:00:43 +00:00
|
|
|
.style(self.colours.graph_style)
|
|
|
|
.labels_style(self.colours.graph_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.bounds([-0.5, 100.5])
|
|
|
|
.labels(&["0%", "100%"]);
|
|
|
|
|
2020-02-17 22:42:51 +00:00
|
|
|
let dataset_vector: Vec<Dataset> = cpu_data
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.rev()
|
2020-02-18 03:59:35 +00:00
|
|
|
.filter_map(|(itx, cpu)| {
|
|
|
|
if app_state.cpu_state.core_show_vec[itx] {
|
|
|
|
Some(
|
|
|
|
Dataset::default()
|
|
|
|
.marker(if app_state.app_config_fields.use_dot {
|
|
|
|
Marker::Dot
|
|
|
|
} else {
|
|
|
|
Marker::Braille
|
|
|
|
})
|
|
|
|
.style(
|
|
|
|
self.colours.cpu_colour_styles
|
|
|
|
[itx % self.colours.cpu_colour_styles.len()],
|
|
|
|
)
|
|
|
|
.data(&cpu.cpu_data[..]),
|
2020-02-17 22:42:51 +00:00
|
|
|
)
|
2020-02-18 03:59:35 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2020-02-17 22:42:51 +00:00
|
|
|
})
|
2020-02-18 03:59:35 +00:00
|
|
|
.collect();
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-17 00:32:21 +00:00
|
|
|
let title = if app_state.is_expanded && !app_state.cpu_state.is_showing_tray {
|
2020-02-13 00:55:58 +00:00
|
|
|
const TITLE_BASE: &str = " CPU ── Esc to go back ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let result_title =
|
|
|
|
format!(" CPU ─{}─ Esc to go back ", "─".repeat(repeat_num as usize));
|
|
|
|
|
|
|
|
result_title
|
|
|
|
} else {
|
|
|
|
" CPU ".to_string()
|
|
|
|
};
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
Chart::default()
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-13 00:55:58 +00:00
|
|
|
.title(&title)
|
|
|
|
.title_style(if app_state.is_expanded {
|
|
|
|
self.colours.highlighted_border_style
|
|
|
|
} else {
|
|
|
|
self.colours.widget_title_style
|
|
|
|
})
|
2020-02-05 03:44:49 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_widget_selected {
|
2020-02-08 19:28:19 +00:00
|
|
|
app::WidgetPosition::Cpu => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
.x_axis(x_axis)
|
|
|
|
.y_axis(y_axis)
|
|
|
|
.datasets(&dataset_vector)
|
|
|
|
.render(f, draw_loc);
|
2019-12-28 03:39:25 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
fn draw_cpu_legend<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let cpu_data: &[ConvertedCpuData] = &(app_state.canvas_data.cpu_data);
|
|
|
|
|
|
|
|
let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64;
|
|
|
|
let start_position = get_start_position(
|
|
|
|
num_rows,
|
2020-02-12 02:16:43 +00:00
|
|
|
&(app_state.app_scroll_positions.scroll_direction),
|
|
|
|
&mut app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.cpu_scroll_state
|
|
|
|
.previous_scroll_position,
|
|
|
|
app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.cpu_scroll_state
|
|
|
|
.current_scroll_position,
|
2019-12-28 03:39:25 +00:00
|
|
|
);
|
|
|
|
|
2020-02-05 04:33:09 +00:00
|
|
|
let sliced_cpu_data = &cpu_data[start_position as usize..];
|
2020-02-05 03:44:49 +00:00
|
|
|
let mut stringified_cpu_data: Vec<Vec<String>> = Vec::new();
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-18 03:59:35 +00:00
|
|
|
for (itx, cpu) in sliced_cpu_data.iter().enumerate() {
|
|
|
|
if app_state.cpu_state.is_showing_tray {
|
2020-02-18 00:25:59 +00:00
|
|
|
stringified_cpu_data.push(vec![
|
|
|
|
cpu.cpu_name.clone(),
|
|
|
|
if app_state.cpu_state.core_show_vec[itx + start_position as usize] {
|
|
|
|
"[*]".to_string()
|
|
|
|
} else {
|
|
|
|
"[ ]".to_string()
|
|
|
|
},
|
|
|
|
]);
|
2020-02-18 03:59:35 +00:00
|
|
|
} else if let Some(cpu_data) = cpu.cpu_data.last() {
|
|
|
|
if app_state.app_config_fields.show_disabled_data
|
|
|
|
|| app_state.cpu_state.core_show_vec[itx]
|
|
|
|
{
|
2020-02-18 00:25:59 +00:00
|
|
|
stringified_cpu_data.push(vec![
|
|
|
|
cpu.cpu_name.clone(),
|
|
|
|
format!("{:.0}%", cpu_data.1.round()),
|
|
|
|
]);
|
2020-02-17 22:42:51 +00:00
|
|
|
}
|
2020-02-05 03:44:49 +00:00
|
|
|
}
|
2020-01-01 22:55:15 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let cpu_rows = stringified_cpu_data
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(itx, cpu_string_row)| {
|
|
|
|
Row::StyledData(
|
|
|
|
cpu_string_row.iter(),
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Cpu => {
|
2020-02-16 22:48:24 +00:00
|
|
|
if itx as u64
|
2020-02-12 02:16:43 +00:00
|
|
|
== app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.cpu_scroll_state
|
|
|
|
.current_scroll_position - start_position
|
2020-02-05 03:44:49 +00:00
|
|
|
{
|
2020-02-08 21:00:43 +00:00
|
|
|
self.colours.currently_selected_text_style
|
2020-02-05 03:44:49 +00:00
|
|
|
} else {
|
2020-02-16 22:48:24 +00:00
|
|
|
self.colours.cpu_colour_styles[itx
|
|
|
|
+ start_position as usize
|
|
|
|
% self.colours.cpu_colour_styles.len()]
|
2020-01-08 04:40:53 +00:00
|
|
|
}
|
2020-01-03 00:07:53 +00:00
|
|
|
}
|
2020-02-08 21:00:43 +00:00
|
|
|
_ => {
|
2020-02-16 22:48:24 +00:00
|
|
|
self.colours.cpu_colour_styles[itx
|
|
|
|
+ start_position as usize % self.colours.cpu_colour_styles.len()]
|
2020-02-08 21:00:43 +00:00
|
|
|
}
|
2020-02-05 03:44:49 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
// Calculate widths
|
|
|
|
let width = f64::from(draw_loc.width);
|
2020-02-18 00:25:59 +00:00
|
|
|
let width_ratios = vec![0.5, 0.5];
|
|
|
|
|
2020-02-16 22:48:24 +00:00
|
|
|
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
|
|
|
|
},
|
|
|
|
);
|
2020-02-05 04:33:09 +00:00
|
|
|
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-17 00:32:21 +00:00
|
|
|
let title = if app_state.cpu_state.is_showing_tray {
|
2020-02-18 00:25:59 +00:00
|
|
|
const TITLE_BASE: &str = " Esc to close ";
|
2020-02-17 00:32:21 +00:00
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
2020-02-17 05:40:39 +00:00
|
|
|
let result_title = format!("{} Esc to close ", "─".repeat(repeat_num as usize));
|
2020-02-17 00:32:21 +00:00
|
|
|
|
|
|
|
result_title
|
|
|
|
} else {
|
|
|
|
"".to_string()
|
|
|
|
};
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Draw
|
2020-02-16 22:48:24 +00:00
|
|
|
Table::new(
|
|
|
|
if app_state.cpu_state.is_showing_tray {
|
2020-02-18 00:25:59 +00:00
|
|
|
CPU_SELECT_LEGEND_HEADER
|
2020-02-16 22:48:24 +00:00
|
|
|
} else {
|
2020-02-18 00:25:59 +00:00
|
|
|
CPU_LEGEND_HEADER
|
2020-02-16 22:48:24 +00:00
|
|
|
}
|
|
|
|
.iter(),
|
|
|
|
cpu_rows,
|
|
|
|
)
|
2020-02-17 00:32:21 +00:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.title(&title)
|
|
|
|
.title_style(if app_state.is_expanded {
|
|
|
|
self.colours.highlighted_border_style
|
|
|
|
} else {
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Cpu => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Cpu => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
|
|
|
}),
|
|
|
|
)
|
2020-02-16 22:48:24 +00:00
|
|
|
.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);
|
2020-02-05 03:44:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn draw_memory_graph<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let mem_data: &[(f64, f64)] = &(app_state.canvas_data.mem_data);
|
|
|
|
let swap_data: &[(f64, f64)] = &(app_state.canvas_data.swap_data);
|
|
|
|
|
2020-02-08 19:28:19 +00:00
|
|
|
let x_axis: Axis<String> = Axis::default().bounds([0.0, TIME_STARTS_FROM as f64]);
|
2020-02-05 03:44:49 +00:00
|
|
|
|
|
|
|
// Offset as the zero value isn't drawn otherwise...
|
|
|
|
let y_axis: Axis<&str> = Axis::default()
|
2020-02-08 21:00:43 +00:00
|
|
|
.style(self.colours.graph_style)
|
|
|
|
.labels_style(self.colours.graph_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.bounds([-0.5, 100.5])
|
|
|
|
.labels(&["0%", "100%"]);
|
|
|
|
|
|
|
|
let mut mem_canvas_vec: Vec<Dataset> = vec![Dataset::default()
|
|
|
|
.name(&app_state.canvas_data.mem_label)
|
2020-02-12 02:16:43 +00:00
|
|
|
.marker(if app_state.app_config_fields.use_dot {
|
2020-02-05 03:44:49 +00:00
|
|
|
Marker::Dot
|
|
|
|
} else {
|
|
|
|
Marker::Braille
|
|
|
|
})
|
2020-02-08 21:39:50 +00:00
|
|
|
.style(self.colours.ram_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.data(&mem_data)];
|
|
|
|
|
|
|
|
if !(&swap_data).is_empty() {
|
|
|
|
mem_canvas_vec.push(
|
|
|
|
Dataset::default()
|
|
|
|
.name(&app_state.canvas_data.swap_label)
|
2020-02-12 02:16:43 +00:00
|
|
|
.marker(if app_state.app_config_fields.use_dot {
|
2020-02-05 03:44:49 +00:00
|
|
|
Marker::Dot
|
|
|
|
} else {
|
|
|
|
Marker::Braille
|
|
|
|
})
|
2020-02-08 21:39:50 +00:00
|
|
|
.style(self.colours.swap_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.data(&swap_data),
|
|
|
|
);
|
|
|
|
}
|
2020-01-11 04:41:16 +00:00
|
|
|
|
2020-02-13 00:55:58 +00:00
|
|
|
let title = if app_state.is_expanded {
|
|
|
|
const TITLE_BASE: &str = " Memory ── Esc to go back ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let result_title = format!(
|
|
|
|
" Memory ─{}─ Esc to go back ",
|
|
|
|
"─".repeat(repeat_num as usize)
|
|
|
|
);
|
|
|
|
|
|
|
|
result_title
|
|
|
|
} else {
|
|
|
|
" Memory ".to_string()
|
|
|
|
};
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
Chart::default()
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-13 00:55:58 +00:00
|
|
|
.title(&title)
|
|
|
|
.title_style(if app_state.is_expanded {
|
|
|
|
self.colours.highlighted_border_style
|
|
|
|
} else {
|
|
|
|
self.colours.widget_title_style
|
|
|
|
})
|
2020-02-05 03:44:49 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_widget_selected {
|
2020-02-08 19:28:19 +00:00
|
|
|
app::WidgetPosition::Mem => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
.x_axis(x_axis)
|
|
|
|
.y_axis(y_axis)
|
|
|
|
.datasets(&mem_canvas_vec)
|
|
|
|
.render(f, draw_loc);
|
|
|
|
}
|
2019-12-28 06:20:05 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
fn draw_network_graph<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let network_data_rx: &[(f64, f64)] = &(app_state.canvas_data.network_data_rx);
|
|
|
|
let network_data_tx: &[(f64, f64)] = &(app_state.canvas_data.network_data_tx);
|
|
|
|
|
2020-02-08 19:28:19 +00:00
|
|
|
let x_axis: Axis<String> = Axis::default().bounds([0.0, 60_000.0]);
|
2020-02-05 03:44:49 +00:00
|
|
|
let y_axis = Axis::default()
|
2020-02-08 21:00:43 +00:00
|
|
|
.style(self.colours.graph_style)
|
|
|
|
.labels_style(self.colours.graph_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.bounds([-0.5, 30_f64])
|
|
|
|
.labels(&["0B", "1KiB", "1MiB", "1GiB"]);
|
2020-02-13 00:55:58 +00:00
|
|
|
|
|
|
|
let title = if app_state.is_expanded {
|
|
|
|
const TITLE_BASE: &str = " Network ── Esc to go back ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let result_title = format!(
|
|
|
|
" Network ─{}─ Esc to go back ",
|
|
|
|
"─".repeat(repeat_num as usize)
|
|
|
|
);
|
|
|
|
|
|
|
|
result_title
|
|
|
|
} else {
|
|
|
|
" Network ".to_string()
|
|
|
|
};
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
Chart::default()
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-13 00:55:58 +00:00
|
|
|
.title(&title)
|
|
|
|
.title_style(if app_state.is_expanded {
|
|
|
|
self.colours.highlighted_border_style
|
|
|
|
} else {
|
|
|
|
self.colours.widget_title_style
|
|
|
|
})
|
2020-02-05 03:44:49 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_widget_selected {
|
2020-02-08 19:28:19 +00:00
|
|
|
app::WidgetPosition::Network => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
}),
|
|
|
|
)
|
|
|
|
.x_axis(x_axis)
|
|
|
|
.y_axis(y_axis)
|
|
|
|
.datasets(&[
|
|
|
|
Dataset::default()
|
2020-02-17 22:42:51 +00:00
|
|
|
.name(&format!("RX: {:7}", app_state.canvas_data.rx_display))
|
2020-02-12 02:16:43 +00:00
|
|
|
.marker(if app_state.app_config_fields.use_dot {
|
2020-02-05 03:44:49 +00:00
|
|
|
Marker::Dot
|
|
|
|
} else {
|
|
|
|
Marker::Braille
|
|
|
|
})
|
2020-02-08 21:39:50 +00:00
|
|
|
.style(self.colours.rx_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.data(&network_data_rx),
|
|
|
|
Dataset::default()
|
2020-02-17 22:42:51 +00:00
|
|
|
.name(&format!("TX: {:7}", app_state.canvas_data.tx_display))
|
2020-02-12 02:16:43 +00:00
|
|
|
.marker(if app_state.app_config_fields.use_dot {
|
2020-02-05 03:44:49 +00:00
|
|
|
Marker::Dot
|
|
|
|
} else {
|
|
|
|
Marker::Braille
|
|
|
|
})
|
2020-02-08 21:39:50 +00:00
|
|
|
.style(self.colours.tx_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.data(&network_data_tx),
|
2020-02-12 02:16:43 +00:00
|
|
|
Dataset::default().name(&format!(
|
|
|
|
"Total RX: {:7}",
|
2020-02-17 22:42:51 +00:00
|
|
|
app_state.canvas_data.total_rx_display
|
2020-02-12 02:16:43 +00:00
|
|
|
)),
|
|
|
|
Dataset::default().name(&format!(
|
|
|
|
"Total TX: {:7}",
|
2020-02-17 22:42:51 +00:00
|
|
|
app_state.canvas_data.total_tx_display
|
2020-02-12 02:16:43 +00:00
|
|
|
)),
|
2020-02-05 03:44:49 +00:00
|
|
|
])
|
|
|
|
.render(f, draw_loc);
|
|
|
|
}
|
2020-01-14 03:06:44 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
fn draw_network_labels<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
|
|
|
) {
|
2020-02-17 22:42:51 +00:00
|
|
|
let rx_display = &app_state.canvas_data.rx_display;
|
|
|
|
let tx_display = &app_state.canvas_data.tx_display;
|
|
|
|
let total_rx_display = &app_state.canvas_data.total_rx_display;
|
|
|
|
let total_tx_display = &app_state.canvas_data.total_tx_display;
|
2020-02-05 03:44:49 +00:00
|
|
|
|
|
|
|
// Gross but I need it to work...
|
2020-02-10 03:19:05 +00:00
|
|
|
let total_network = vec![vec![
|
|
|
|
rx_display,
|
|
|
|
tx_display,
|
|
|
|
total_rx_display,
|
|
|
|
total_tx_display,
|
|
|
|
]];
|
2020-02-08 19:28:19 +00:00
|
|
|
let mapped_network = total_network
|
|
|
|
.iter()
|
|
|
|
.map(|val| Row::StyledData(val.iter(), self.colours.text_style));
|
2020-02-05 03:44:49 +00:00
|
|
|
|
|
|
|
// Calculate widths
|
2020-02-10 03:19:05 +00:00
|
|
|
let width_ratios: Vec<f64> = vec![0.25, 0.25, 0.25, 0.25];
|
|
|
|
let lens: &Vec<usize> = &NETWORK_HEADERS_LENS;
|
2020-02-05 03:44:49 +00:00
|
|
|
let width = f64::from(draw_loc.width);
|
|
|
|
|
|
|
|
let variable_intrinsic_results =
|
|
|
|
get_variable_intrinsic_widths(width as u16, &width_ratios, lens);
|
2020-02-05 04:33:09 +00:00
|
|
|
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
2020-02-05 03:44:49 +00:00
|
|
|
|
|
|
|
// Draw
|
2020-02-10 03:19:05 +00:00
|
|
|
Table::new(NETWORK_HEADERS.iter(), mapped_network)
|
2020-02-13 00:55:58 +00:00
|
|
|
.block(Block::default().borders(Borders::ALL).border_style(
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Network => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
|
|
|
},
|
|
|
|
))
|
2020-02-10 03:19:05 +00:00
|
|
|
.header_style(self.colours.table_header_style)
|
|
|
|
.style(self.colours.text_style)
|
|
|
|
.widths(
|
|
|
|
&(intrinsic_widths
|
2020-02-10 05:16:11 +00:00
|
|
|
.iter()
|
2020-02-10 03:19:05 +00:00
|
|
|
.map(|calculated_width| Constraint::Length(*calculated_width as u16))
|
|
|
|
.collect::<Vec<_>>()),
|
|
|
|
)
|
|
|
|
.render(f, draw_loc);
|
2020-02-05 03:44:49 +00:00
|
|
|
}
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
fn draw_temp_table<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let temp_sensor_data: &[Vec<String>] = &(app_state.canvas_data.temp_sensor_data);
|
|
|
|
|
|
|
|
let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64;
|
|
|
|
let start_position = get_start_position(
|
|
|
|
num_rows,
|
2020-02-12 02:16:43 +00:00
|
|
|
&(app_state.app_scroll_positions.scroll_direction),
|
|
|
|
&mut app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.temp_scroll_state
|
|
|
|
.previous_scroll_position,
|
|
|
|
app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.temp_scroll_state
|
|
|
|
.current_scroll_position,
|
2020-01-26 21:44:24 +00:00
|
|
|
);
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 04:33:09 +00:00
|
|
|
let sliced_vec = &(temp_sensor_data[start_position as usize..]);
|
2020-02-05 03:44:49 +00:00
|
|
|
let mut temp_row_counter: i64 = 0;
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let temperature_rows = sliced_vec.iter().map(|temp_row| {
|
|
|
|
Row::StyledData(
|
|
|
|
temp_row.iter(),
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Temp => {
|
|
|
|
if temp_row_counter as u64
|
2020-02-12 02:16:43 +00:00
|
|
|
== app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.temp_scroll_state
|
|
|
|
.current_scroll_position - start_position
|
2020-02-05 03:44:49 +00:00
|
|
|
{
|
|
|
|
temp_row_counter = -1;
|
2020-02-08 21:00:43 +00:00
|
|
|
self.colours.currently_selected_text_style
|
2020-02-05 03:44:49 +00:00
|
|
|
} else {
|
|
|
|
if temp_row_counter >= 0 {
|
|
|
|
temp_row_counter += 1;
|
|
|
|
}
|
2020-02-08 21:39:50 +00:00
|
|
|
self.colours.text_style
|
2020-02-05 03:44:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-08 21:39:50 +00:00
|
|
|
_ => self.colours.text_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
});
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Calculate widths
|
|
|
|
let width = f64::from(draw_loc.width);
|
|
|
|
let width_ratios = [0.5, 0.5];
|
|
|
|
let variable_intrinsic_results =
|
|
|
|
get_variable_intrinsic_widths(width as u16, &width_ratios, &TEMP_HEADERS_LENS);
|
2020-02-05 04:33:09 +00:00
|
|
|
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-13 00:55:58 +00:00
|
|
|
let title = if app_state.is_expanded {
|
|
|
|
const TITLE_BASE: &str = " Temperatures ── Esc to go back ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let result_title = format!(
|
|
|
|
" Temperatures ─{}─ Esc to go back ",
|
|
|
|
"─".repeat(repeat_num as usize)
|
|
|
|
);
|
|
|
|
|
|
|
|
result_title
|
|
|
|
} else {
|
|
|
|
" Temperatures ".to_string()
|
|
|
|
};
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Draw
|
|
|
|
Table::new(TEMP_HEADERS.iter(), temperature_rows)
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-13 00:55:58 +00:00
|
|
|
.title(&title)
|
|
|
|
.title_style(if app_state.is_expanded {
|
|
|
|
self.colours.highlighted_border_style
|
|
|
|
} else {
|
|
|
|
self.colours.widget_title_style
|
|
|
|
})
|
2020-02-05 03:44:49 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_widget_selected {
|
2020-02-08 19:28:19 +00:00
|
|
|
app::WidgetPosition::Temp => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
}),
|
|
|
|
)
|
2020-02-08 21:00:43 +00:00
|
|
|
.header_style(self.colours.table_header_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.widths(
|
|
|
|
&(intrinsic_widths
|
2020-02-10 05:16:11 +00:00
|
|
|
.iter()
|
2020-02-05 04:33:09 +00:00
|
|
|
.map(|calculated_width| Constraint::Length(*calculated_width as u16))
|
2020-02-05 03:44:49 +00:00
|
|
|
.collect::<Vec<_>>()),
|
|
|
|
)
|
|
|
|
.render(f, draw_loc);
|
2020-01-11 22:30:04 +00:00
|
|
|
}
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
fn draw_disk_table<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let disk_data: &[Vec<String>] = &(app_state.canvas_data.disk_data);
|
|
|
|
let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64;
|
|
|
|
let start_position = get_start_position(
|
|
|
|
num_rows,
|
2020-02-12 02:16:43 +00:00
|
|
|
&(app_state.app_scroll_positions.scroll_direction),
|
|
|
|
&mut app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.disk_scroll_state
|
|
|
|
.previous_scroll_position,
|
|
|
|
app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.disk_scroll_state
|
|
|
|
.current_scroll_position,
|
2020-02-05 03:44:49 +00:00
|
|
|
);
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 04:33:09 +00:00
|
|
|
let sliced_vec = &disk_data[start_position as usize..];
|
2020-02-05 03:44:49 +00:00
|
|
|
let mut disk_counter: i64 = 0;
|
|
|
|
|
|
|
|
let disk_rows = sliced_vec.iter().map(|disk| {
|
|
|
|
Row::StyledData(
|
|
|
|
disk.iter(),
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Disk => {
|
|
|
|
if disk_counter as u64
|
2020-02-12 02:16:43 +00:00
|
|
|
== app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.disk_scroll_state
|
|
|
|
.current_scroll_position - start_position
|
2020-02-05 03:44:49 +00:00
|
|
|
{
|
|
|
|
disk_counter = -1;
|
2020-02-08 21:00:43 +00:00
|
|
|
self.colours.currently_selected_text_style
|
2020-02-05 03:44:49 +00:00
|
|
|
} else {
|
|
|
|
if disk_counter >= 0 {
|
|
|
|
disk_counter += 1;
|
|
|
|
}
|
2020-02-08 21:39:50 +00:00
|
|
|
self.colours.text_style
|
2020-01-03 00:07:53 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-08 21:39:50 +00:00
|
|
|
_ => self.colours.text_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
});
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Calculate widths
|
2020-02-08 19:28:19 +00:00
|
|
|
// TODO: [PRETTY] Ellipsis on strings?
|
2020-02-05 03:44:49 +00:00
|
|
|
let width = f64::from(draw_loc.width);
|
|
|
|
let width_ratios = [0.2, 0.15, 0.13, 0.13, 0.13, 0.13, 0.13];
|
|
|
|
let variable_intrinsic_results =
|
|
|
|
get_variable_intrinsic_widths(width as u16, &width_ratios, &DISK_HEADERS_LENS);
|
2020-02-05 04:33:09 +00:00
|
|
|
let intrinsic_widths = &variable_intrinsic_results.0[0..variable_intrinsic_results.1];
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-13 00:55:58 +00:00
|
|
|
let title = if app_state.is_expanded {
|
|
|
|
const TITLE_BASE: &str = " Disk ── Esc to go back ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let result_title = format!(
|
|
|
|
" Disk ─{}─ Esc to go back ",
|
|
|
|
"─".repeat(repeat_num as usize)
|
|
|
|
);
|
|
|
|
|
|
|
|
result_title
|
|
|
|
} else {
|
|
|
|
" Disk ".to_string()
|
|
|
|
};
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
// Draw!
|
|
|
|
Table::new(DISK_HEADERS.iter(), disk_rows)
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-13 00:55:58 +00:00
|
|
|
.title(&title)
|
|
|
|
.title_style(if app_state.is_expanded {
|
|
|
|
self.colours.highlighted_border_style
|
|
|
|
} else {
|
|
|
|
self.colours.widget_title_style
|
|
|
|
})
|
2020-02-05 03:44:49 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_widget_selected {
|
2020-02-08 19:28:19 +00:00
|
|
|
app::WidgetPosition::Disk => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
}),
|
|
|
|
)
|
2020-02-08 21:00:43 +00:00
|
|
|
.header_style(self.colours.table_header_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.widths(
|
|
|
|
&(intrinsic_widths
|
2020-02-10 05:16:11 +00:00
|
|
|
.iter()
|
2020-02-05 04:33:09 +00:00
|
|
|
.map(|calculated_width| Constraint::Length(*calculated_width as u16))
|
2020-02-05 03:44:49 +00:00
|
|
|
.collect::<Vec<_>>()),
|
|
|
|
)
|
|
|
|
.render(f, draw_loc);
|
|
|
|
}
|
2020-02-03 04:36:44 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
fn draw_search_field<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let width = max(0, draw_loc.width as i64 - 34) as u64;
|
|
|
|
let query = app_state.get_current_search_query();
|
|
|
|
let shrunk_query = if query.len() < width as usize {
|
|
|
|
query
|
2020-01-16 04:03:23 +00:00
|
|
|
} else {
|
2020-02-05 03:44:49 +00:00
|
|
|
&query[(query.len() - width as usize)..]
|
|
|
|
};
|
2020-01-17 02:33:06 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let cursor_position = app_state.get_cursor_position();
|
2020-01-17 02:33:06 +00:00
|
|
|
|
2020-02-08 21:39:50 +00:00
|
|
|
let query_with_cursor: Vec<Text> =
|
|
|
|
if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected {
|
|
|
|
if cursor_position >= query.len() {
|
|
|
|
let mut q = vec![Text::styled(
|
|
|
|
shrunk_query.to_string(),
|
|
|
|
self.colours.text_style,
|
|
|
|
)];
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-08 21:39:50 +00:00
|
|
|
q.push(Text::styled(
|
|
|
|
" ".to_string(),
|
|
|
|
self.colours.currently_selected_text_style,
|
|
|
|
));
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-08 21:39:50 +00:00
|
|
|
q
|
|
|
|
} else {
|
|
|
|
shrunk_query
|
|
|
|
.chars()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(itx, c)| {
|
|
|
|
if let app::WidgetPosition::ProcessSearch =
|
|
|
|
app_state.current_widget_selected
|
|
|
|
{
|
|
|
|
if itx == cursor_position {
|
|
|
|
return Text::styled(
|
|
|
|
c.to_string(),
|
|
|
|
self.colours.currently_selected_text_style,
|
|
|
|
);
|
|
|
|
}
|
2020-02-08 19:28:19 +00:00
|
|
|
}
|
2020-02-08 21:39:50 +00:00
|
|
|
Text::styled(c.to_string(), self.colours.text_style)
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vec![Text::styled(
|
|
|
|
shrunk_query.to_string(),
|
|
|
|
self.colours.text_style,
|
|
|
|
)]
|
|
|
|
};
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-18 03:59:35 +00:00
|
|
|
let mut search_text = vec![if app_state.is_grouped() {
|
|
|
|
Text::styled("Search by Name: ", self.colours.table_header_style)
|
|
|
|
} else if app_state.process_search_state.is_searching_with_pid {
|
2020-02-05 03:44:49 +00:00
|
|
|
Text::styled(
|
|
|
|
"Search by PID (Tab for Name): ",
|
2020-02-08 21:00:43 +00:00
|
|
|
self.colours.table_header_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
Text::styled(
|
|
|
|
"Search by Name (Tab for PID): ",
|
2020-02-08 21:00:43 +00:00
|
|
|
self.colours.table_header_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
)
|
|
|
|
}];
|
|
|
|
|
|
|
|
// Text options shamelessly stolen from VS Code.
|
2020-02-15 22:19:49 +00:00
|
|
|
let mut option_text = vec![];
|
|
|
|
for _ in 0..(draw_loc.height - 3) {
|
|
|
|
option_text.push(Text::raw("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
let option_row = vec![
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled("Match Case (Alt+C)", self.colours.table_header_style),
|
2020-02-16 01:16:05 +00:00
|
|
|
if !app_state.process_search_state.is_ignoring_case {
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled("[*]", self.colours.table_header_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
} else {
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled("[ ]", self.colours.table_header_style)
|
2020-02-03 04:15:24 +00:00
|
|
|
},
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled(" ", self.colours.table_header_style),
|
|
|
|
Text::styled("Match Whole Word (Alt+W)", self.colours.table_header_style),
|
2020-02-16 01:16:05 +00:00
|
|
|
if app_state.process_search_state.is_searching_whole_word {
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled("[*]", self.colours.table_header_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
} else {
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled("[ ]", self.colours.table_header_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
},
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled(" ", self.colours.table_header_style),
|
|
|
|
Text::styled("Use Regex (Alt+R)", self.colours.table_header_style),
|
2020-02-16 01:16:05 +00:00
|
|
|
if app_state.process_search_state.is_searching_with_regex {
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled("[*]", self.colours.table_header_style)
|
2020-01-08 04:39:52 +00:00
|
|
|
} else {
|
2020-02-08 21:00:43 +00:00
|
|
|
Text::styled("[ ]", self.colours.table_header_style)
|
2020-01-08 04:39:52 +00:00
|
|
|
},
|
2020-01-02 04:39:47 +00:00
|
|
|
];
|
2020-02-15 22:19:49 +00:00
|
|
|
option_text.extend(option_row);
|
2020-02-05 03:44:49 +00:00
|
|
|
|
|
|
|
search_text.extend(query_with_cursor);
|
|
|
|
search_text.extend(option_text);
|
|
|
|
|
2020-02-10 02:27:02 +00:00
|
|
|
const TITLE_BASE: &str = " Esc to close ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
2020-02-10 00:23:11 +00:00
|
|
|
let title = format!("{} Esc to close ", "─".repeat(repeat_num as usize));
|
|
|
|
|
2020-02-17 22:42:51 +00:00
|
|
|
let current_border_style: Style = if app_state
|
|
|
|
.process_search_state
|
|
|
|
.search_state
|
|
|
|
.is_invalid_search
|
|
|
|
{
|
2020-02-10 02:27:02 +00:00
|
|
|
Style::default().fg(Color::Rgb(255, 0, 0))
|
|
|
|
} else {
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::ProcessSearch => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
Paragraph::new(search_text.iter())
|
2020-02-08 21:00:43 +00:00
|
|
|
.block(
|
|
|
|
Block::default()
|
|
|
|
.borders(Borders::ALL)
|
2020-02-10 00:23:11 +00:00
|
|
|
.title(&title)
|
2020-02-10 02:27:02 +00:00
|
|
|
.title_style(current_border_style)
|
|
|
|
.border_style(current_border_style),
|
2020-02-08 21:00:43 +00:00
|
|
|
)
|
2020-02-08 21:39:50 +00:00
|
|
|
.style(self.colours.text_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.alignment(Alignment::Left)
|
|
|
|
.wrap(false)
|
|
|
|
.render(f, draw_loc);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw_processes_table<B: backend::Backend>(
|
|
|
|
&self, f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
|
|
|
) {
|
|
|
|
let process_data: &[ConvertedProcessData] = &app_state.canvas_data.finalized_process_data;
|
|
|
|
|
|
|
|
// Admittedly this is kinda a hack... but we need to:
|
|
|
|
// * Scroll
|
|
|
|
// * Show/hide elements based on scroll position
|
|
|
|
//
|
|
|
|
// As such, we use a process_counter to know when we've
|
|
|
|
// hit the process we've currently scrolled to.
|
|
|
|
// We also need to move the list - we can
|
|
|
|
// do so by hiding some elements!
|
|
|
|
let num_rows = max(0, i64::from(draw_loc.height) - 5) as u64;
|
|
|
|
|
|
|
|
let position = get_start_position(
|
|
|
|
num_rows,
|
2020-02-12 02:16:43 +00:00
|
|
|
&(app_state.app_scroll_positions.scroll_direction),
|
|
|
|
&mut app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.process_scroll_state
|
|
|
|
.previous_scroll_position,
|
|
|
|
app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.process_scroll_state
|
|
|
|
.current_scroll_position,
|
2020-02-05 03:44:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
let start_position = if position >= process_data.len() as u64 {
|
|
|
|
std::cmp::max(0, process_data.len() as i64 - 1) as u64
|
|
|
|
} else {
|
|
|
|
position
|
|
|
|
};
|
|
|
|
|
2020-02-05 04:33:09 +00:00
|
|
|
let sliced_vec = &(process_data[start_position as usize..]);
|
2020-02-05 03:44:49 +00:00
|
|
|
let mut process_counter: i64 = 0;
|
|
|
|
|
|
|
|
// Draw!
|
|
|
|
let process_rows = sliced_vec.iter().map(|process| {
|
|
|
|
let stringified_process_vec: Vec<String> = vec![
|
|
|
|
if app_state.is_grouped() {
|
|
|
|
process.group_pids.len().to_string()
|
|
|
|
} else {
|
|
|
|
process.pid.to_string()
|
|
|
|
},
|
|
|
|
process.name.clone(),
|
|
|
|
format!("{:.1}%", process.cpu_usage),
|
|
|
|
format!("{:.1}%", process.mem_usage),
|
|
|
|
];
|
|
|
|
Row::StyledData(
|
|
|
|
stringified_process_vec.into_iter(),
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Process => {
|
|
|
|
if process_counter as u64
|
2020-02-12 02:16:43 +00:00
|
|
|
== app_state
|
|
|
|
.app_scroll_positions
|
|
|
|
.process_scroll_state
|
|
|
|
.current_scroll_position - start_position
|
2020-02-05 03:44:49 +00:00
|
|
|
{
|
|
|
|
process_counter = -1;
|
2020-02-08 21:00:43 +00:00
|
|
|
self.colours.currently_selected_text_style
|
2020-02-05 03:44:49 +00:00
|
|
|
} else {
|
|
|
|
if process_counter >= 0 {
|
|
|
|
process_counter += 1;
|
|
|
|
}
|
2020-02-08 21:39:50 +00:00
|
|
|
self.colours.text_style
|
2020-01-03 00:07:53 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-08 21:39:50 +00:00
|
|
|
_ => self.colours.text_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
});
|
2019-12-28 03:39:25 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
use app::data_harvester::processes::ProcessSorting;
|
|
|
|
let mut pid_or_name = if app_state.is_grouped() {
|
|
|
|
"Count"
|
|
|
|
} else {
|
|
|
|
"PID(p)"
|
|
|
|
}
|
|
|
|
.to_string();
|
|
|
|
let mut name = "Name(n)".to_string();
|
|
|
|
let mut cpu = "CPU%(c)".to_string();
|
|
|
|
let mut mem = "Mem%(m)".to_string();
|
2020-01-11 22:30:04 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
let direction_val = if app_state.process_sorting_reverse {
|
|
|
|
"⯆".to_string()
|
|
|
|
} else {
|
|
|
|
"⯅".to_string()
|
|
|
|
};
|
|
|
|
|
|
|
|
match app_state.process_sorting_type {
|
|
|
|
ProcessSorting::CPU => cpu += &direction_val,
|
|
|
|
ProcessSorting::MEM => mem += &direction_val,
|
|
|
|
ProcessSorting::PID => pid_or_name += &direction_val,
|
|
|
|
ProcessSorting::NAME => name += &direction_val,
|
|
|
|
};
|
|
|
|
|
|
|
|
let process_headers = [pid_or_name, name, cpu, mem];
|
|
|
|
let process_headers_lens: Vec<usize> = process_headers
|
|
|
|
.iter()
|
|
|
|
.map(|entry| entry.len())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
// Calculate widths
|
|
|
|
let width = f64::from(draw_loc.width);
|
|
|
|
let width_ratios = [0.2, 0.4, 0.2, 0.2];
|
|
|
|
let variable_intrinsic_results =
|
|
|
|
get_variable_intrinsic_widths(width as u16, &width_ratios, &process_headers_lens);
|
2020-02-05 04:33:09 +00:00
|
|
|
let intrinsic_widths = &(variable_intrinsic_results.0)[0..variable_intrinsic_results.1];
|
2020-02-05 03:44:49 +00:00
|
|
|
|
2020-02-18 03:59:35 +00:00
|
|
|
let title =
|
|
|
|
if app_state.is_expanded && !app_state.process_search_state.search_state.is_enabled {
|
|
|
|
const TITLE_BASE: &str = " Processes ── Esc to go back ";
|
|
|
|
let repeat_num = max(
|
|
|
|
0,
|
|
|
|
draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2,
|
|
|
|
);
|
|
|
|
let result_title = format!(
|
|
|
|
" Processes ─{}─ Esc to go back ",
|
|
|
|
"─".repeat(repeat_num as usize)
|
|
|
|
);
|
2020-02-13 00:55:58 +00:00
|
|
|
|
2020-02-18 03:59:35 +00:00
|
|
|
result_title
|
|
|
|
} else {
|
|
|
|
" Processes ".to_string()
|
|
|
|
};
|
2020-02-13 00:55:58 +00:00
|
|
|
|
2020-02-05 03:44:49 +00:00
|
|
|
Table::new(process_headers.iter(), process_rows)
|
|
|
|
.block(
|
|
|
|
Block::default()
|
2020-02-13 00:55:58 +00:00
|
|
|
.title(&title)
|
|
|
|
.title_style(if app_state.is_expanded {
|
|
|
|
match app_state.current_widget_selected {
|
|
|
|
app::WidgetPosition::Process => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
self.colours.widget_title_style
|
|
|
|
})
|
2020-02-05 03:44:49 +00:00
|
|
|
.borders(Borders::ALL)
|
|
|
|
.border_style(match app_state.current_widget_selected {
|
2020-02-08 19:28:19 +00:00
|
|
|
app::WidgetPosition::Process => self.colours.highlighted_border_style,
|
|
|
|
_ => self.colours.border_style,
|
2020-02-05 03:44:49 +00:00
|
|
|
}),
|
|
|
|
)
|
2020-02-08 21:00:43 +00:00
|
|
|
.header_style(self.colours.table_header_style)
|
2020-02-05 03:44:49 +00:00
|
|
|
.widths(
|
|
|
|
&(intrinsic_widths
|
2020-02-10 05:16:11 +00:00
|
|
|
.iter()
|
2020-02-05 04:33:09 +00:00
|
|
|
.map(|calculated_width| Constraint::Length(*calculated_width as u16))
|
2020-02-05 03:44:49 +00:00
|
|
|
.collect::<Vec<_>>()),
|
|
|
|
)
|
|
|
|
.render(f, draw_loc);
|
|
|
|
}
|
2019-12-28 03:39:25 +00:00
|
|
|
}
|