Formatting changes to be a bit more strict on line length
This commit is contained in:
parent
5a32404ed4
commit
0f2b4a7ba5
|
@ -1,4 +1,4 @@
|
|||
max_width = 150
|
||||
max_width = 100
|
||||
newline_style = "Unix"
|
||||
reorder_imports = true
|
||||
control_brace_style = "ClosingNextLine"
|
||||
|
|
56
src/app.rs
56
src/app.rs
|
@ -60,7 +60,8 @@ pub struct App {
|
|||
|
||||
impl App {
|
||||
pub fn new(
|
||||
show_average_cpu: bool, temperature_type: temperature::TemperatureType, update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool,
|
||||
show_average_cpu: bool, temperature_type: temperature::TemperatureType,
|
||||
update_rate_in_milliseconds: u64, use_dot: bool, left_legend: bool,
|
||||
use_current_cpu_total: bool,
|
||||
) -> App {
|
||||
App {
|
||||
|
@ -151,7 +152,10 @@ impl App {
|
|||
// Forbid any char key presses when showing a dialog box...
|
||||
if !self.is_in_dialog() {
|
||||
let current_key_press_inst = Instant::now();
|
||||
if current_key_press_inst.duration_since(self.last_key_press).as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS {
|
||||
if current_key_press_inst
|
||||
.duration_since(self.last_key_press)
|
||||
.as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS
|
||||
{
|
||||
self.reset_multi_tap_keys();
|
||||
}
|
||||
self.last_key_press = current_key_press_inst;
|
||||
|
@ -163,7 +167,8 @@ impl App {
|
|||
self.awaiting_second_char = false;
|
||||
self.second_char = ' ';
|
||||
|
||||
let current_process = &self.canvas_data.process_data[self.currently_selected_process_position as usize];
|
||||
let current_process = &self.canvas_data.process_data
|
||||
[self.currently_selected_process_position as usize];
|
||||
self.to_delete_process = Some(current_process.clone());
|
||||
self.show_dd = true;
|
||||
self.reset_multi_tap_keys();
|
||||
|
@ -188,7 +193,9 @@ impl App {
|
|||
}
|
||||
'c' => {
|
||||
match self.process_sorting_type {
|
||||
processes::ProcessSorting::CPU => self.process_sorting_reverse = !self.process_sorting_reverse,
|
||||
processes::ProcessSorting::CPU => {
|
||||
self.process_sorting_reverse = !self.process_sorting_reverse
|
||||
}
|
||||
_ => {
|
||||
self.process_sorting_type = processes::ProcessSorting::CPU;
|
||||
self.process_sorting_reverse = true;
|
||||
|
@ -199,7 +206,9 @@ impl App {
|
|||
}
|
||||
'm' => {
|
||||
match self.process_sorting_type {
|
||||
processes::ProcessSorting::MEM => self.process_sorting_reverse = !self.process_sorting_reverse,
|
||||
processes::ProcessSorting::MEM => {
|
||||
self.process_sorting_reverse = !self.process_sorting_reverse
|
||||
}
|
||||
_ => {
|
||||
self.process_sorting_type = processes::ProcessSorting::MEM;
|
||||
self.process_sorting_reverse = true;
|
||||
|
@ -212,7 +221,9 @@ impl App {
|
|||
// Disable if grouping
|
||||
if !self.enable_grouping {
|
||||
match self.process_sorting_type {
|
||||
processes::ProcessSorting::PID => self.process_sorting_reverse = !self.process_sorting_reverse,
|
||||
processes::ProcessSorting::PID => {
|
||||
self.process_sorting_reverse = !self.process_sorting_reverse
|
||||
}
|
||||
_ => {
|
||||
self.process_sorting_type = processes::ProcessSorting::PID;
|
||||
self.process_sorting_reverse = false;
|
||||
|
@ -224,7 +235,9 @@ impl App {
|
|||
}
|
||||
'n' => {
|
||||
match self.process_sorting_type {
|
||||
processes::ProcessSorting::NAME => self.process_sorting_reverse = !self.process_sorting_reverse,
|
||||
processes::ProcessSorting::NAME => {
|
||||
self.process_sorting_reverse = !self.process_sorting_reverse
|
||||
}
|
||||
_ => {
|
||||
self.process_sorting_type = processes::ProcessSorting::NAME;
|
||||
self.process_sorting_reverse = false;
|
||||
|
@ -339,15 +352,25 @@ impl App {
|
|||
pub fn skip_to_last(&mut self) {
|
||||
if !self.is_in_dialog() {
|
||||
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
|
||||
}
|
||||
ApplicationPosition::Cpu => {
|
||||
if let Some(cpu_package) = self.data.list_of_cpu_packages.last() {
|
||||
if self.show_average_cpu {
|
||||
self.currently_selected_cpu_table_position = cpu_package.cpu_vec.len() as i64;
|
||||
self.currently_selected_cpu_table_position =
|
||||
cpu_package.cpu_vec.len() as i64;
|
||||
} else {
|
||||
self.currently_selected_cpu_table_position = cpu_package.cpu_vec.len() as i64 - 1;
|
||||
self.currently_selected_cpu_table_position =
|
||||
cpu_package.cpu_vec.len() as i64 - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -403,7 +426,8 @@ impl App {
|
|||
|
||||
fn change_process_position(&mut self, num_to_change_by: i64) {
|
||||
if self.currently_selected_process_position + num_to_change_by >= 0
|
||||
&& self.currently_selected_process_position + num_to_change_by < self.data.list_of_processes.len() as i64
|
||||
&& self.currently_selected_process_position + num_to_change_by
|
||||
< self.data.list_of_processes.len() as i64
|
||||
{
|
||||
self.currently_selected_process_position += num_to_change_by;
|
||||
}
|
||||
|
@ -411,7 +435,8 @@ impl App {
|
|||
|
||||
fn change_temp_position(&mut self, num_to_change_by: i64) {
|
||||
if self.currently_selected_temperature_position + num_to_change_by >= 0
|
||||
&& self.currently_selected_temperature_position + num_to_change_by < self.data.list_of_temperature_sensor.len() as i64
|
||||
&& self.currently_selected_temperature_position + num_to_change_by
|
||||
< self.data.list_of_temperature_sensor.len() as i64
|
||||
{
|
||||
self.currently_selected_temperature_position += num_to_change_by;
|
||||
}
|
||||
|
@ -419,7 +444,8 @@ impl App {
|
|||
|
||||
fn change_disk_position(&mut self, num_to_change_by: i64) {
|
||||
if self.currently_selected_disk_position + num_to_change_by >= 0
|
||||
&& self.currently_selected_disk_position + num_to_change_by < self.data.list_of_disks.len() as i64
|
||||
&& self.currently_selected_disk_position + num_to_change_by
|
||||
< self.data.list_of_disks.len() as i64
|
||||
{
|
||||
self.currently_selected_disk_position += num_to_change_by;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,12 @@ pub async fn get_disk_usage_list() -> crate::utils::error::Result<Vec<DiskData>>
|
|||
free_space: usage.free().get::<information::megabyte>(),
|
||||
used_space: usage.used().get::<information::megabyte>(),
|
||||
total_space: usage.total().get::<information::megabyte>(),
|
||||
mount_point: Box::from(partition.mount_point().to_str().unwrap_or("Name Unavailable")),
|
||||
mount_point: Box::from(
|
||||
partition
|
||||
.mount_point()
|
||||
.to_str()
|
||||
.unwrap_or("Name Unavailable"),
|
||||
),
|
||||
name: Box::from(
|
||||
partition
|
||||
.device()
|
||||
|
|
|
@ -13,7 +13,8 @@ pub async fn get_mem_data_list() -> crate::utils::error::Result<MemData> {
|
|||
|
||||
Ok(MemData {
|
||||
mem_total_in_mb: memory.total().get::<information::megabyte>(),
|
||||
mem_used_in_mb: memory.total().get::<information::megabyte>() - memory.available().get::<information::megabyte>(),
|
||||
mem_used_in_mb: memory.total().get::<information::megabyte>()
|
||||
- memory.available().get::<information::megabyte>(),
|
||||
instant: Instant::now(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,7 +15,8 @@ pub struct NetworkData {
|
|||
}
|
||||
|
||||
pub async fn get_network_data(
|
||||
sys: &System, prev_net_rx_bytes: &mut u64, prev_net_tx_bytes: &mut u64, prev_net_access_time: &mut std::time::Instant,
|
||||
sys: &System, prev_net_rx_bytes: &mut u64, prev_net_tx_bytes: &mut u64,
|
||||
prev_net_access_time: &mut std::time::Instant,
|
||||
) -> crate::utils::error::Result<NetworkData> {
|
||||
if cfg!(target_os = "windows") {
|
||||
let network_data = sys.get_network();
|
||||
|
|
|
@ -28,7 +28,9 @@ pub struct ProcessData {
|
|||
pub pid_vec: Option<Vec<u32>>, // Note that this is literally never unless we are in grouping mode. This is to save rewriting time.
|
||||
}
|
||||
|
||||
fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> error::Result<(f64, f64)> {
|
||||
fn cpu_usage_calculation(
|
||||
prev_idle: &mut f64, prev_non_idle: &mut f64,
|
||||
) -> error::Result<(f64, f64)> {
|
||||
// From SO answer: https://stackoverflow.com/a/23376195
|
||||
let mut path = std::path::PathBuf::new();
|
||||
path.push("/proc");
|
||||
|
@ -91,12 +93,18 @@ fn cpu_usage_calculation(prev_idle: &mut f64, prev_non_idle: &mut f64) -> error:
|
|||
1_f64
|
||||
};
|
||||
|
||||
let cpu_percentage = if total_delta != 0_f64 { result / total_delta } else { 0_f64 };
|
||||
let cpu_percentage = if total_delta != 0_f64 {
|
||||
result / total_delta
|
||||
} else {
|
||||
0_f64
|
||||
};
|
||||
|
||||
Ok((result, cpu_percentage))
|
||||
}
|
||||
|
||||
fn get_ordering<T: std::cmp::PartialOrd>(a_val: T, b_val: T, reverse_order: bool) -> std::cmp::Ordering {
|
||||
fn get_ordering<T: std::cmp::PartialOrd>(
|
||||
a_val: T, b_val: T, reverse_order: bool,
|
||||
) -> std::cmp::Ordering {
|
||||
match a_val.partial_cmp(&b_val) {
|
||||
Some(x) => match x {
|
||||
Ordering::Greater => {
|
||||
|
@ -137,11 +145,15 @@ fn get_process_cpu_stats(pid: u32) -> std::io::Result<f64> {
|
|||
|
||||
/// Note that cpu_percentage should be represented WITHOUT the \times 100 factor!
|
||||
fn linux_cpu_usage(
|
||||
pid: u32, cpu_usage: f64, cpu_percentage: f64, previous_pid_stats: &mut HashMap<String, (f64, Instant)>, use_current_cpu_total: bool,
|
||||
pid: u32, cpu_usage: f64, cpu_percentage: f64,
|
||||
previous_pid_stats: &mut HashMap<String, (f64, Instant)>, use_current_cpu_total: bool,
|
||||
) -> std::io::Result<f64> {
|
||||
// Based heavily on https://stackoverflow.com/a/23376195 and https://stackoverflow.com/a/1424556
|
||||
let before_proc_val: f64 = if previous_pid_stats.contains_key(&pid.to_string()) {
|
||||
previous_pid_stats.get(&pid.to_string()).unwrap_or(&(0_f64, Instant::now())).0
|
||||
previous_pid_stats
|
||||
.get(&pid.to_string())
|
||||
.unwrap_or(&(0_f64, Instant::now()))
|
||||
.0
|
||||
} else {
|
||||
0_f64
|
||||
};
|
||||
|
@ -156,7 +168,9 @@ fn linux_cpu_usage(
|
|||
(after_proc_val - before_proc_val) / cpu_usage * 100_f64
|
||||
);*/
|
||||
|
||||
let entry = previous_pid_stats.entry(pid.to_string()).or_insert((after_proc_val, Instant::now()));
|
||||
let entry = previous_pid_stats
|
||||
.entry(pid.to_string())
|
||||
.or_insert((after_proc_val, Instant::now()));
|
||||
*entry = (after_proc_val, Instant::now());
|
||||
if use_current_cpu_total {
|
||||
Ok((after_proc_val - before_proc_val) / cpu_usage * 100_f64)
|
||||
|
@ -166,7 +180,8 @@ fn linux_cpu_usage(
|
|||
}
|
||||
|
||||
fn convert_ps(
|
||||
process: &str, cpu_usage: f64, cpu_percentage: f64, prev_pid_stats: &mut HashMap<String, (f64, Instant)>, use_current_cpu_total: bool,
|
||||
process: &str, cpu_usage: f64, cpu_percentage: f64,
|
||||
prev_pid_stats: &mut HashMap<String, (f64, Instant)>, use_current_cpu_total: bool,
|
||||
) -> std::io::Result<ProcessData> {
|
||||
if process.trim().to_string().is_empty() {
|
||||
return Ok(ProcessData {
|
||||
|
@ -179,22 +194,39 @@ fn convert_ps(
|
|||
});
|
||||
}
|
||||
|
||||
let pid = (&process[..11]).trim().to_string().parse::<u32>().unwrap_or(0);
|
||||
let pid = (&process[..11])
|
||||
.trim()
|
||||
.to_string()
|
||||
.parse::<u32>()
|
||||
.unwrap_or(0);
|
||||
let command = (&process[11..61]).trim().to_string();
|
||||
let mem_usage_percent = Some((&process[62..]).trim().to_string().parse::<f64>().unwrap_or(0_f64));
|
||||
let mem_usage_percent = Some(
|
||||
(&process[62..])
|
||||
.trim()
|
||||
.to_string()
|
||||
.parse::<f64>()
|
||||
.unwrap_or(0_f64),
|
||||
);
|
||||
|
||||
Ok(ProcessData {
|
||||
pid,
|
||||
command,
|
||||
mem_usage_percent,
|
||||
mem_usage_kb: None,
|
||||
cpu_usage_percent: linux_cpu_usage(pid, cpu_usage, cpu_percentage, prev_pid_stats, use_current_cpu_total)?,
|
||||
cpu_usage_percent: linux_cpu_usage(
|
||||
pid,
|
||||
cpu_usage,
|
||||
cpu_percentage,
|
||||
prev_pid_stats,
|
||||
use_current_cpu_total,
|
||||
)?,
|
||||
pid_vec: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_sorted_processes_list(
|
||||
sys: &System, prev_idle: &mut f64, prev_non_idle: &mut f64, prev_pid_stats: &mut std::collections::HashMap<String, (f64, Instant)>,
|
||||
sys: &System, prev_idle: &mut f64, prev_non_idle: &mut f64,
|
||||
prev_pid_stats: &mut std::collections::HashMap<String, (f64, Instant)>,
|
||||
use_current_cpu_total: bool,
|
||||
) -> crate::utils::error::Result<Vec<ProcessData>> {
|
||||
let mut process_vector: Vec<ProcessData> = Vec::new();
|
||||
|
@ -202,7 +234,9 @@ pub fn get_sorted_processes_list(
|
|||
if cfg!(target_os = "linux") {
|
||||
// Linux specific - this is a massive pain... ugh.
|
||||
|
||||
let ps_result = Command::new("ps").args(&["-axo", "pid:10,comm:50,%mem:5", "--noheader"]).output()?;
|
||||
let ps_result = Command::new("ps")
|
||||
.args(&["-axo", "pid:10,comm:50,%mem:5", "--noheader"])
|
||||
.output()?;
|
||||
let ps_stdout = String::from_utf8_lossy(&ps_result.stdout);
|
||||
let split_string = ps_stdout.split('\n');
|
||||
//debug!("{:?}", split_string);
|
||||
|
@ -211,7 +245,13 @@ pub fn get_sorted_processes_list(
|
|||
let process_stream = split_string.collect::<Vec<&str>>();
|
||||
|
||||
for process in process_stream {
|
||||
if let Ok(process_object) = convert_ps(process, cpu_usage, cpu_percentage, prev_pid_stats, use_current_cpu_total) {
|
||||
if let Ok(process_object) = convert_ps(
|
||||
process,
|
||||
cpu_usage,
|
||||
cpu_percentage,
|
||||
prev_pid_stats,
|
||||
use_current_cpu_total,
|
||||
) {
|
||||
if !process_object.command.is_empty() {
|
||||
process_vector.push(process_object);
|
||||
}
|
||||
|
@ -259,20 +299,28 @@ pub fn get_sorted_processes_list(
|
|||
Ok(process_vector)
|
||||
}
|
||||
|
||||
pub fn sort_processes(process_vector: &mut Vec<ProcessData>, sorting_method: &ProcessSorting, reverse_order: bool) {
|
||||
pub fn sort_processes(
|
||||
process_vector: &mut Vec<ProcessData>, sorting_method: &ProcessSorting, reverse_order: bool,
|
||||
) {
|
||||
// Always sort alphabetically first!
|
||||
process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, false));
|
||||
|
||||
match sorting_method {
|
||||
ProcessSorting::CPU => {
|
||||
process_vector.sort_by(|a, b| get_ordering(a.cpu_usage_percent, b.cpu_usage_percent, reverse_order));
|
||||
process_vector.sort_by(|a, b| {
|
||||
get_ordering(a.cpu_usage_percent, b.cpu_usage_percent, reverse_order)
|
||||
});
|
||||
}
|
||||
ProcessSorting::MEM => {
|
||||
process_vector.sort_by(|a, b| get_ordering(a.mem_usage_percent, b.mem_usage_percent, reverse_order));
|
||||
process_vector.sort_by(|a, b| {
|
||||
get_ordering(a.mem_usage_percent, b.mem_usage_percent, reverse_order)
|
||||
});
|
||||
}
|
||||
ProcessSorting::PID => {
|
||||
process_vector.sort_by(|a, b| get_ordering(a.pid, b.pid, reverse_order));
|
||||
}
|
||||
ProcessSorting::NAME => process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, reverse_order)),
|
||||
ProcessSorting::NAME => {
|
||||
process_vector.sort_by(|a, b| get_ordering(&a.command, &b.command, reverse_order))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ impl Default for TemperatureType {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) -> crate::utils::error::Result<Vec<TempData>> {
|
||||
pub async fn get_temperature_data(
|
||||
sys: &System, temp_type: &TemperatureType,
|
||||
) -> crate::utils::error::Result<Vec<TempData>> {
|
||||
let mut temperature_vec: Vec<TempData> = Vec::new();
|
||||
|
||||
if cfg!(target_os = "linux") {
|
||||
|
@ -32,9 +34,17 @@ pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) ->
|
|||
temperature_vec.push(TempData {
|
||||
component_name: Box::from(sensor.unit()),
|
||||
temperature: match temp_type {
|
||||
TemperatureType::Celsius => sensor.current().get::<thermodynamic_temperature::degree_celsius>(),
|
||||
TemperatureType::Kelvin => sensor.current().get::<thermodynamic_temperature::kelvin>(),
|
||||
TemperatureType::Fahrenheit => sensor.current().get::<thermodynamic_temperature::degree_fahrenheit>(),
|
||||
TemperatureType::Celsius => sensor
|
||||
.current()
|
||||
.get::<thermodynamic_temperature::degree_celsius>(
|
||||
),
|
||||
TemperatureType::Kelvin => {
|
||||
sensor.current().get::<thermodynamic_temperature::kelvin>()
|
||||
}
|
||||
TemperatureType::Fahrenheit => sensor
|
||||
.current()
|
||||
.get::<thermodynamic_temperature::degree_fahrenheit>(
|
||||
),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -47,7 +57,9 @@ pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) ->
|
|||
temperature: match temp_type {
|
||||
TemperatureType::Celsius => component.get_temperature(),
|
||||
TemperatureType::Kelvin => component.get_temperature() + 273.15,
|
||||
TemperatureType::Fahrenheit => (component.get_temperature() * (9.0 / 5.0)) + 32.0,
|
||||
TemperatureType::Fahrenheit => {
|
||||
(component.get_temperature() * (9.0 / 5.0)) + 32.0
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -65,7 +77,11 @@ pub async fn get_temperature_data(sys: &System, temp_type: &TemperatureType) ->
|
|||
None => Ordering::Equal,
|
||||
});
|
||||
|
||||
temperature_vec.sort_by(|a, b| a.component_name.partial_cmp(&b.component_name).unwrap_or(Ordering::Equal));
|
||||
temperature_vec.sort_by(|a, b| {
|
||||
a.component_name
|
||||
.partial_cmp(&b.component_name)
|
||||
.unwrap_or(Ordering::Equal)
|
||||
});
|
||||
|
||||
Ok(temperature_vec)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,9 @@ pub fn kill_process_given_pid(pid: u32) -> crate::utils::error::Result<()> {
|
|||
});
|
||||
} else {
|
||||
return Err(BottomError::GenericError {
|
||||
message: "Sorry, support operating systems outside the main three are not implemented yet!".to_string(),
|
||||
message:
|
||||
"Sorry, support operating systems outside the main three are not implemented yet!"
|
||||
.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
328
src/canvas.rs
328
src/canvas.rs
|
@ -24,7 +24,9 @@ lazy_static! {
|
|||
Text::raw("q, Ctrl-c to quit.\n"),
|
||||
Text::raw("Ctrl-r to reset all data.\n"),
|
||||
Text::raw("f to toggle freezing and unfreezing the display.\n"),
|
||||
Text::raw("Ctrl+Up/k, Ctrl+Down/j, Ctrl+Left/h, Ctrl+Right/l to navigate between panels.\n"),
|
||||
Text::raw(
|
||||
"Ctrl+Up/k, Ctrl+Down/j, Ctrl+Left/h, Ctrl+Right/l to navigate between panels.\n"
|
||||
),
|
||||
Text::raw("Up and Down scrolls through a list.\n"),
|
||||
Text::raw("Esc to close a dialog window (help or dd confirmation).\n"),
|
||||
Text::raw("? to get this help screen.\n"),
|
||||
|
@ -37,7 +39,8 @@ lazy_static! {
|
|||
];
|
||||
static ref COLOUR_LIST: Vec<Color> = gen_n_colours(constants::NUM_COLOURS);
|
||||
static ref CANVAS_BORDER_STYLE: Style = Style::default().fg(BORDER_STYLE_COLOUR);
|
||||
static ref CANVAS_HIGHLIGHTED_BORDER_STYLE: Style = Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR);
|
||||
static ref CANVAS_HIGHLIGHTED_BORDER_STYLE: Style =
|
||||
Style::default().fg(HIGHLIGHTED_BORDER_STYLE_COLOUR);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -85,7 +88,13 @@ fn gen_n_colours(num_to_gen: i32) -> Vec<Color> {
|
|||
}
|
||||
|
||||
// Generate colours
|
||||
let mut colour_vec: Vec<Color> = vec![Color::LightCyan, Color::LightYellow, Color::Red, Color::Green, Color::LightMagenta];
|
||||
let mut colour_vec: Vec<Color> = vec![
|
||||
Color::LightCyan,
|
||||
Color::LightYellow,
|
||||
Color::Red,
|
||||
Color::Green,
|
||||
Color::LightMagenta,
|
||||
];
|
||||
|
||||
let mut h: f32 = 0.4; // We don't need random colours... right?
|
||||
for _i in 0..num_to_gen {
|
||||
|
@ -97,7 +106,9 @@ fn gen_n_colours(num_to_gen: i32) -> Vec<Color> {
|
|||
colour_vec
|
||||
}
|
||||
|
||||
pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mut app::App) -> error::Result<()> {
|
||||
pub fn draw_data<B: backend::Backend>(
|
||||
terminal: &mut Terminal<B>, app_state: &mut app::App,
|
||||
) -> error::Result<()> {
|
||||
terminal.autoresize()?;
|
||||
terminal.draw(|mut f| {
|
||||
if app_state.show_help {
|
||||
|
@ -105,17 +116,35 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
|
|||
let vertical_dialog_chunk = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([Constraint::Percentage(32), Constraint::Percentage(40), Constraint::Percentage(28)].as_ref())
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Percentage(32),
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Percentage(28),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(f.size());
|
||||
|
||||
let middle_dialog_chunk = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.margin(0)
|
||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref())
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Percentage(30),
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Percentage(30),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(vertical_dialog_chunk[1]);
|
||||
|
||||
Paragraph::new(HELP_TEXT.iter())
|
||||
.block(Block::default().title("Help (Press Esc to close)").borders(Borders::ALL))
|
||||
.block(
|
||||
Block::default()
|
||||
.title("Help (Press Esc to close)")
|
||||
.borders(Borders::ALL),
|
||||
)
|
||||
.style(Style::default().fg(Color::Gray))
|
||||
.alignment(Alignment::Left)
|
||||
.wrap(true)
|
||||
|
@ -124,20 +153,41 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
|
|||
let vertical_dialog_chunk = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([Constraint::Percentage(40), Constraint::Percentage(20), Constraint::Percentage(40)].as_ref())
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Percentage(20),
|
||||
Constraint::Percentage(40),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(f.size());
|
||||
|
||||
let middle_dialog_chunk = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.margin(0)
|
||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(40), Constraint::Percentage(30)].as_ref())
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Percentage(30),
|
||||
Constraint::Percentage(40),
|
||||
Constraint::Percentage(30),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(vertical_dialog_chunk[1]);
|
||||
|
||||
if let Some(dd_err) = app_state.dd_err.clone() {
|
||||
let dd_text = [Text::raw(format!("\nFailure to properly kill the process - {}", dd_err))];
|
||||
let dd_text = [Text::raw(format!(
|
||||
"\nFailure to properly kill the process - {}",
|
||||
dd_err
|
||||
))];
|
||||
|
||||
Paragraph::new(dd_text.iter())
|
||||
.block(Block::default().title("Kill Process Error (Press Esc to close)").borders(Borders::ALL))
|
||||
.block(
|
||||
Block::default()
|
||||
.title("Kill Process Error (Press Esc to close)")
|
||||
.borders(Borders::ALL),
|
||||
)
|
||||
.style(Style::default().fg(Color::Gray))
|
||||
.alignment(Alignment::Center)
|
||||
.wrap(true)
|
||||
|
@ -170,7 +220,14 @@ pub fn draw_data<B: backend::Backend>(terminal: &mut Terminal<B>, app_state: &mu
|
|||
let vertical_chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints([Constraint::Percentage(33), Constraint::Percentage(34), Constraint::Percentage(34)].as_ref())
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Percentage(33),
|
||||
Constraint::Percentage(34),
|
||||
Constraint::Percentage(34),
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(f.size());
|
||||
|
||||
let middle_chunks = Layout::default()
|
||||
|
@ -279,7 +336,10 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d
|
|||
|
||||
cpu_entries_vec.push((
|
||||
Style::default().fg(COLOUR_LIST[(i - avg_cpu_exist_offset) % COLOUR_LIST.len()]),
|
||||
cpu.cpu_data.iter().map(<(f64, f64)>::from).collect::<Vec<_>>(),
|
||||
cpu.cpu_data
|
||||
.iter()
|
||||
.map(<(f64, f64)>::from)
|
||||
.collect::<Vec<_>>(),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -287,7 +347,11 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d
|
|||
if let Some(avg_cpu_entry) = cpu_data.first() {
|
||||
cpu_entries_vec.push((
|
||||
Style::default().fg(COLOUR_LIST[(cpu_data.len() - 1) % COLOUR_LIST.len()]),
|
||||
avg_cpu_entry.cpu_data.iter().map(<(f64, f64)>::from).collect::<Vec<_>>(),
|
||||
avg_cpu_entry
|
||||
.cpu_data
|
||||
.iter()
|
||||
.map(<(f64, f64)>::from)
|
||||
.collect::<Vec<_>>(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +359,11 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d
|
|||
for cpu_entry in &cpu_entries_vec {
|
||||
dataset_vector.push(
|
||||
Dataset::default()
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.marker(if app_state.use_dot {
|
||||
Marker::Dot
|
||||
} else {
|
||||
Marker::Braille
|
||||
})
|
||||
.style(cpu_entry.0)
|
||||
.data(&(cpu_entry.1)),
|
||||
);
|
||||
|
@ -317,7 +385,9 @@ fn draw_cpu_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App, d
|
|||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
|
||||
fn draw_cpu_legend<B: backend::Backend>(
|
||||
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 = i64::from(draw_loc.height) - 4;
|
||||
|
@ -333,47 +403,55 @@ fn draw_cpu_legend<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
|
|||
|
||||
for cpu in sliced_cpu_data {
|
||||
if let Some(cpu_data) = cpu.cpu_data.last() {
|
||||
stringified_cpu_data.push(vec![cpu.cpu_name.clone(), format!("{:.0}%", cpu_data.usage.round())]);
|
||||
stringified_cpu_data.push(vec![
|
||||
cpu.cpu_name.clone(),
|
||||
format!("{:.0}%", cpu_data.usage.round()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
let mut cpu_row_counter = 0;
|
||||
|
||||
let cpu_rows = stringified_cpu_data.iter().enumerate().map(|(itx, cpu_string_row)| {
|
||||
Row::StyledData(
|
||||
cpu_string_row.iter(),
|
||||
match app_state.current_application_position {
|
||||
app::ApplicationPosition::Cpu => {
|
||||
if cpu_row_counter == app_state.currently_selected_cpu_table_position - start_position {
|
||||
cpu_row_counter = -1;
|
||||
Style::default().fg(Color::Black).bg(Color::Cyan)
|
||||
} else {
|
||||
if cpu_row_counter >= 0 {
|
||||
cpu_row_counter += 1;
|
||||
let cpu_rows = stringified_cpu_data
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(itx, cpu_string_row)| {
|
||||
Row::StyledData(
|
||||
cpu_string_row.iter(),
|
||||
match app_state.current_application_position {
|
||||
app::ApplicationPosition::Cpu => {
|
||||
if cpu_row_counter
|
||||
== app_state.currently_selected_cpu_table_position - start_position
|
||||
{
|
||||
cpu_row_counter = -1;
|
||||
Style::default().fg(Color::Black).bg(Color::Cyan)
|
||||
} else {
|
||||
if cpu_row_counter >= 0 {
|
||||
cpu_row_counter += 1;
|
||||
}
|
||||
Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()])
|
||||
}
|
||||
Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()])
|
||||
}
|
||||
}
|
||||
_ => Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]),
|
||||
},
|
||||
)
|
||||
});
|
||||
_ => Style::default().fg(COLOUR_LIST[itx % COLOUR_LIST.len()]),
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
Table::new(["CPU", "Use%"].iter(), cpu_rows)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::Cpu => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
.block(Block::default().borders(Borders::ALL).border_style(
|
||||
match app_state.current_application_position {
|
||||
app::ApplicationPosition::Cpu => *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_memory_table<B: backend::Backend>(_f: &mut Frame<B>, _app_state: &app::App, _draw_loc: Rect) {
|
||||
fn _draw_memory_table<B: backend::Backend>(
|
||||
_f: &mut Frame<B>, _app_state: &app::App, _draw_loc: Rect,
|
||||
) {
|
||||
todo!("Not implemented yet..."); // TODO: For basic mode
|
||||
}
|
||||
|
||||
|
@ -391,17 +469,23 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App
|
|||
.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
|
||||
);
|
||||
"{: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)
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.marker(if app_state.use_dot {
|
||||
Marker::Dot
|
||||
} else {
|
||||
Marker::Braille
|
||||
})
|
||||
.style(Style::default().fg(COLOUR_LIST[0]))
|
||||
.data(&mem_data)];
|
||||
|
||||
|
@ -409,16 +493,22 @@ fn draw_memory_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::App
|
|||
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
|
||||
);
|
||||
"{: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)
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.marker(if app_state.use_dot {
|
||||
Marker::Dot
|
||||
} else {
|
||||
Marker::Braille
|
||||
})
|
||||
.style(Style::default().fg(COLOUR_LIST[1]))
|
||||
.data(&swap_data),
|
||||
);
|
||||
|
@ -446,7 +536,9 @@ fn draw_network_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::Ap
|
|||
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);
|
||||
|
||||
let x_axis: Axis<String> = Axis::default().style(Style::default().fg(GRAPH_COLOUR)).bounds([0.0, 600_000.0]);
|
||||
let x_axis: Axis<String> = Axis::default()
|
||||
.style(Style::default().fg(GRAPH_COLOUR))
|
||||
.bounds([0.0, 600_000.0]);
|
||||
let y_axis = Axis::default()
|
||||
.style(Style::default().fg(GRAPH_COLOUR))
|
||||
.bounds([-0.5, 30_f64])
|
||||
|
@ -465,18 +557,28 @@ fn draw_network_graph<B: backend::Backend>(f: &mut Frame<B>, app_state: &app::Ap
|
|||
.y_axis(y_axis)
|
||||
.datasets(&[
|
||||
Dataset::default()
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.marker(if app_state.use_dot {
|
||||
Marker::Dot
|
||||
} else {
|
||||
Marker::Braille
|
||||
})
|
||||
.style(Style::default().fg(COLOUR_LIST[0]))
|
||||
.data(&network_data_rx),
|
||||
Dataset::default()
|
||||
.marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille })
|
||||
.marker(if app_state.use_dot {
|
||||
Marker::Dot
|
||||
} else {
|
||||
Marker::Braille
|
||||
})
|
||||
.style(Style::default().fg(COLOUR_LIST[1]))
|
||||
.data(&network_data_tx),
|
||||
])
|
||||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_network_labels<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
|
||||
fn draw_network_labels<B: backend::Backend>(
|
||||
f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
||||
) {
|
||||
let rx_display: String = app_state.canvas_data.rx_display.clone();
|
||||
let tx_display: String = app_state.canvas_data.tx_display.clone();
|
||||
let total_rx_display: String = app_state.canvas_data.total_rx_display.clone();
|
||||
|
@ -484,7 +586,12 @@ fn draw_network_labels<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut ap
|
|||
|
||||
// Gross but I need it to work...
|
||||
let total_network = if cfg!(not(target_os = "windows")) {
|
||||
vec![vec![rx_display, tx_display, total_rx_display, total_tx_display]]
|
||||
vec![vec![
|
||||
rx_display,
|
||||
tx_display,
|
||||
total_rx_display,
|
||||
total_tx_display,
|
||||
]]
|
||||
} else {
|
||||
vec![vec![rx_display, tx_display]]
|
||||
};
|
||||
|
@ -499,14 +606,12 @@ fn draw_network_labels<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut ap
|
|||
.iter(),
|
||||
mapped_network,
|
||||
)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::Network => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
.block(Block::default().borders(Borders::ALL).border_style(
|
||||
match app_state.current_application_position {
|
||||
app::ApplicationPosition::Network => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
},
|
||||
))
|
||||
.header_style(Style::default().fg(Color::LightBlue))
|
||||
.widths(&if cfg!(not(target_os = "windows")) {
|
||||
vec![
|
||||
|
@ -521,7 +626,9 @@ fn draw_network_labels<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut ap
|
|||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
|
||||
fn draw_temp_table<B: backend::Backend>(
|
||||
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 = i64::from(draw_loc.height) - 4;
|
||||
|
@ -540,7 +647,9 @@ fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
|
|||
temp_row.iter(),
|
||||
match app_state.current_application_position {
|
||||
app::ApplicationPosition::Temp => {
|
||||
if temp_row_counter == app_state.currently_selected_temperature_position - start_position {
|
||||
if temp_row_counter
|
||||
== app_state.currently_selected_temperature_position - start_position
|
||||
{
|
||||
temp_row_counter = -1;
|
||||
Style::default().fg(Color::Black).bg(Color::Cyan)
|
||||
} else {
|
||||
|
@ -569,7 +678,9 @@ fn draw_temp_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::A
|
|||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_disk_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
|
||||
fn draw_disk_table<B: backend::Backend>(
|
||||
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 = i64::from(draw_loc.height) - 4;
|
||||
let start_position = get_start_position(
|
||||
|
@ -602,31 +713,40 @@ 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")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::Disk => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
.header_style(Style::default().fg(Color::LightBlue).modifier(Modifier::BOLD))
|
||||
.widths(&[
|
||||
Constraint::Percentage(18),
|
||||
Constraint::Percentage(14),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
])
|
||||
.render(f, draw_loc);
|
||||
Table::new(
|
||||
["Disk", "Mount", "Used", "Total", "Free", "R/s", "W/s"].iter(),
|
||||
disk_rows,
|
||||
)
|
||||
.block(
|
||||
Block::default()
|
||||
.title("Disk")
|
||||
.borders(Borders::ALL)
|
||||
.border_style(match app_state.current_application_position {
|
||||
app::ApplicationPosition::Disk => *CANVAS_HIGHLIGHTED_BORDER_STYLE,
|
||||
_ => *CANVAS_BORDER_STYLE,
|
||||
}),
|
||||
)
|
||||
.header_style(
|
||||
Style::default()
|
||||
.fg(Color::LightBlue)
|
||||
.modifier(Modifier::BOLD),
|
||||
)
|
||||
.widths(&[
|
||||
Constraint::Percentage(18),
|
||||
Constraint::Percentage(14),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
Constraint::Percentage(11),
|
||||
])
|
||||
.render(f, draw_loc);
|
||||
}
|
||||
|
||||
fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect) {
|
||||
fn draw_processes_table<B: backend::Backend>(
|
||||
f: &mut Frame<B>, app_state: &mut app::App, draw_loc: Rect,
|
||||
) {
|
||||
let process_data: &[ConvertedProcessData] = &(app_state.canvas_data.process_data);
|
||||
|
||||
// Admittedly this is kinda a hack... but we need to:
|
||||
|
@ -661,7 +781,9 @@ fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut a
|
|||
stringified_process_vec.into_iter(),
|
||||
match app_state.current_application_position {
|
||||
app::ApplicationPosition::Process => {
|
||||
if process_counter == app_state.currently_selected_process_position - start_position {
|
||||
if process_counter
|
||||
== app_state.currently_selected_process_position - start_position
|
||||
{
|
||||
process_counter = -1;
|
||||
Style::default().fg(Color::Black).bg(Color::Cyan)
|
||||
} else {
|
||||
|
@ -678,7 +800,12 @@ fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut a
|
|||
|
||||
{
|
||||
use app::data_collection::processes::ProcessSorting;
|
||||
let mut pid_or_name = if app_state.is_grouped() { "Count" } else { "PID(p)" }.to_string();
|
||||
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();
|
||||
|
@ -718,7 +845,8 @@ fn draw_processes_table<B: backend::Backend>(f: &mut Frame<B>, app_state: &mut a
|
|||
}
|
||||
|
||||
fn get_start_position(
|
||||
num_rows: i64, scroll_direction: &app::ScrollDirection, previous_position: &mut i64, currently_selected_position: &mut i64,
|
||||
num_rows: i64, scroll_direction: &app::ScrollDirection, previous_position: &mut i64,
|
||||
currently_selected_position: &mut i64,
|
||||
) -> i64 {
|
||||
match scroll_direction {
|
||||
app::ScrollDirection::DOWN => {
|
||||
|
@ -738,7 +866,11 @@ fn get_start_position(
|
|||
}
|
||||
|
||||
if *currently_selected_position == *previous_position - 1 {
|
||||
*previous_position = if *previous_position > 0 { *previous_position - 1 } else { 0 };
|
||||
*previous_position = if *previous_position > 0 {
|
||||
*previous_position - 1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
*previous_position
|
||||
} else {
|
||||
*previous_position
|
||||
|
|
|
@ -50,7 +50,9 @@ impl From<&CpuPoint> for (f64, f64) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_temp_row(app_data: &data_collection::Data, temp_type: &data_collection::temperature::TemperatureType) -> Vec<Vec<String>> {
|
||||
pub fn update_temp_row(
|
||||
app_data: &data_collection::Data, temp_type: &data_collection::temperature::TemperatureType,
|
||||
) -> Vec<Vec<String>> {
|
||||
let mut sensor_vector: Vec<Vec<String>> = Vec::new();
|
||||
|
||||
if (&app_data.list_of_temperature_sensor).is_empty() {
|
||||
|
@ -84,15 +86,23 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec<Vec<String>> {
|
|||
|
||||
let io_hashmap = &io_package.io_hash;
|
||||
let prev_io_hashmap = &prev_io_package.io_hash;
|
||||
let time_difference = io_package.instant.duration_since(prev_io_package.instant).as_secs_f64();
|
||||
if io_hashmap.contains_key(trimmed_mount) && prev_io_hashmap.contains_key(trimmed_mount) {
|
||||
let time_difference = io_package
|
||||
.instant
|
||||
.duration_since(prev_io_package.instant)
|
||||
.as_secs_f64();
|
||||
if io_hashmap.contains_key(trimmed_mount)
|
||||
&& prev_io_hashmap.contains_key(trimmed_mount)
|
||||
{
|
||||
// Ideally change this...
|
||||
let ele = &io_hashmap[trimmed_mount];
|
||||
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 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, false);
|
||||
let converted_write = get_simple_byte_values(write_bytes_per_sec, false);
|
||||
let converted_write =
|
||||
get_simple_byte_values(write_bytes_per_sec, false);
|
||||
final_result = (
|
||||
format!("{:.*}{}/s", 0, converted_read.0, converted_read.1),
|
||||
format!("{:.*}{}/s", 0, converted_write.0, converted_write.1),
|
||||
|
@ -109,9 +119,15 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec<Vec<String>> {
|
|||
disk_vector.push(vec![
|
||||
disk.name.to_string(),
|
||||
disk.mount_point.to_string(),
|
||||
format!("{:.0}%", disk.used_space as f64 / disk.total_space as f64 * 100_f64),
|
||||
format!(
|
||||
"{:.0}%",
|
||||
disk.used_space as f64 / disk.total_space as f64 * 100_f64
|
||||
),
|
||||
format!("{:.*}{}", 0, converted_free_space.0, converted_free_space.1),
|
||||
format!("{:.*}{}", 0, converted_total_space.0, converted_total_space.1),
|
||||
format!(
|
||||
"{:.*}{}",
|
||||
0, converted_total_space.0, converted_total_space.1
|
||||
),
|
||||
io_activity.0,
|
||||
io_activity.1,
|
||||
]);
|
||||
|
@ -142,20 +158,28 @@ pub fn update_process_row(app_data: &data_collection::Data) -> Vec<ConvertedProc
|
|||
0_f64
|
||||
}
|
||||
),
|
||||
group_count: if let Some(pid_vec) = &process.pid_vec { pid_vec.len() as u32 } else { 0 },
|
||||
group_count: if let Some(pid_vec) = &process.pid_vec {
|
||||
pid_vec.len() as u32
|
||||
} else {
|
||||
0
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
process_vector
|
||||
}
|
||||
|
||||
pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Data) -> Vec<ConvertedCpuData> {
|
||||
pub fn update_cpu_data_points(
|
||||
show_avg_cpu: bool, app_data: &data_collection::Data,
|
||||
) -> Vec<ConvertedCpuData> {
|
||||
let mut cpu_data_vector: Vec<ConvertedCpuData> = Vec::new();
|
||||
let mut cpu_collection: Vec<Vec<CpuPoint>> = Vec::new();
|
||||
|
||||
if !app_data.list_of_cpu_packages.is_empty() {
|
||||
// I'm sorry for the following if statement but I couldn't be bothered here...
|
||||
for cpu_num in (if show_avg_cpu { 0 } else { 1 })..app_data.list_of_cpu_packages.last().unwrap().cpu_vec.len() {
|
||||
for cpu_num in (if show_avg_cpu { 0 } else { 1 })
|
||||
..app_data.list_of_cpu_packages.last().unwrap().cpu_vec.len()
|
||||
{
|
||||
let mut this_cpu_data: Vec<CpuPoint> = Vec::new();
|
||||
|
||||
for data in &app_data.list_of_cpu_packages {
|
||||
|
@ -163,7 +187,10 @@ pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Da
|
|||
let current_cpu_usage = data.cpu_vec[cpu_num].cpu_usage;
|
||||
|
||||
let new_entry = CpuPoint {
|
||||
time: ((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(),
|
||||
time: ((TIME_STARTS_FROM as f64
|
||||
- current_time.duration_since(data.instant).as_millis() as f64)
|
||||
* 10_f64)
|
||||
.floor(),
|
||||
usage: current_cpu_usage,
|
||||
};
|
||||
|
||||
|
@ -171,8 +198,12 @@ pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Da
|
|||
if let Some(previous_element_data) = this_cpu_data.last().cloned() {
|
||||
for idx in 0..50 {
|
||||
this_cpu_data.push(CpuPoint {
|
||||
time: previous_element_data.time + ((new_entry.time - previous_element_data.time) / 50.0 * f64::from(idx)),
|
||||
usage: previous_element_data.usage + ((new_entry.usage - previous_element_data.usage) / 50.0 * f64::from(idx)),
|
||||
time: previous_element_data.time
|
||||
+ ((new_entry.time - previous_element_data.time) / 50.0
|
||||
* f64::from(idx)),
|
||||
usage: previous_element_data.usage
|
||||
+ ((new_entry.usage - previous_element_data.usage) / 50.0
|
||||
* f64::from(idx)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +233,9 @@ pub fn update_cpu_data_points(show_avg_cpu: bool, app_data: &data_collection::Da
|
|||
if show_avg_cpu && i == 0 {
|
||||
"AVG"
|
||||
} else {
|
||||
&*(app_data.list_of_cpu_packages.last().unwrap().cpu_vec[i + if show_avg_cpu { 0 } else { 1 }].cpu_name)
|
||||
&*(app_data.list_of_cpu_packages.last().unwrap().cpu_vec
|
||||
[i + if show_avg_cpu { 0 } else { 1 }]
|
||||
.cpu_name)
|
||||
}
|
||||
)
|
||||
.to_uppercase(),
|
||||
|
@ -250,7 +283,10 @@ fn convert_mem_data(mem_data: &[data_collection::mem::MemData]) -> Vec<(f64, f64
|
|||
for data in mem_data {
|
||||
let current_time = std::time::Instant::now();
|
||||
let new_entry = (
|
||||
((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(),
|
||||
((TIME_STARTS_FROM as f64
|
||||
- current_time.duration_since(data.instant).as_millis() as f64)
|
||||
* 10_f64)
|
||||
.floor(),
|
||||
if data.mem_total_in_mb == 0 {
|
||||
-1000.0
|
||||
} else {
|
||||
|
@ -263,8 +299,10 @@ fn convert_mem_data(mem_data: &[data_collection::mem::MemData]) -> Vec<(f64, f64
|
|||
let previous_element_data = *(result.last().unwrap());
|
||||
for idx in 0..50 {
|
||||
result.push((
|
||||
previous_element_data.0 + ((new_entry.0 - previous_element_data.0) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.1 + ((new_entry.1 - previous_element_data.1) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.0
|
||||
+ ((new_entry.0 - previous_element_data.0) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.1
|
||||
+ ((new_entry.1 - previous_element_data.1) / 50.0 * f64::from(idx)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -279,19 +317,35 @@ pub fn update_network_data_points(app_data: &data_collection::Data) -> Converted
|
|||
convert_network_data_points(&app_data.network)
|
||||
}
|
||||
|
||||
pub fn convert_network_data_points(network_data: &[data_collection::network::NetworkData]) -> ConvertedNetworkData {
|
||||
pub fn convert_network_data_points(
|
||||
network_data: &[data_collection::network::NetworkData],
|
||||
) -> ConvertedNetworkData {
|
||||
let mut rx: Vec<(f64, f64)> = Vec::new();
|
||||
let mut tx: Vec<(f64, f64)> = Vec::new();
|
||||
|
||||
for data in network_data {
|
||||
let current_time = std::time::Instant::now();
|
||||
let rx_data = (
|
||||
((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(),
|
||||
if data.rx > 0 { (data.rx as f64).log(2.0) } else { 0.0 },
|
||||
((TIME_STARTS_FROM as f64
|
||||
- current_time.duration_since(data.instant).as_millis() as f64)
|
||||
* 10_f64)
|
||||
.floor(),
|
||||
if data.rx > 0 {
|
||||
(data.rx as f64).log(2.0)
|
||||
} else {
|
||||
0.0
|
||||
},
|
||||
);
|
||||
let tx_data = (
|
||||
((TIME_STARTS_FROM as f64 - current_time.duration_since(data.instant).as_millis() as f64) * 10_f64).floor(),
|
||||
if data.tx > 0 { (data.tx as f64).log(2.0) } else { 0.0 },
|
||||
((TIME_STARTS_FROM as f64
|
||||
- current_time.duration_since(data.instant).as_millis() as f64)
|
||||
* 10_f64)
|
||||
.floor(),
|
||||
if data.tx > 0 {
|
||||
(data.tx as f64).log(2.0)
|
||||
} else {
|
||||
0.0
|
||||
},
|
||||
);
|
||||
|
||||
//debug!("Plotting: {:?} bytes rx, {:?} bytes tx", rx_data, tx_data);
|
||||
|
@ -301,8 +355,10 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
|
|||
let previous_element_data = *(rx.last().unwrap());
|
||||
for idx in 0..50 {
|
||||
rx.push((
|
||||
previous_element_data.0 + ((rx_data.0 - previous_element_data.0) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.1 + ((rx_data.1 - previous_element_data.1) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.0
|
||||
+ ((rx_data.0 - previous_element_data.0) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.1
|
||||
+ ((rx_data.1 - previous_element_data.1) / 50.0 * f64::from(idx)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -312,8 +368,10 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
|
|||
let previous_element_data = *(tx.last().unwrap());
|
||||
for idx in 0..50 {
|
||||
tx.push((
|
||||
previous_element_data.0 + ((tx_data.0 - previous_element_data.0) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.1 + ((tx_data.1 - previous_element_data.1) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.0
|
||||
+ ((tx_data.0 - previous_element_data.0) / 50.0 * f64::from(idx)),
|
||||
previous_element_data.1
|
||||
+ ((tx_data.1 - previous_element_data.1) / 50.0 * f64::from(idx)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -336,7 +394,10 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
|
|||
}
|
||||
let rx_display = format!("{:.*}{}", 1, rx_converted_result.0, rx_converted_result.1);
|
||||
let total_rx_display = if cfg!(not(target_os = "windows")) {
|
||||
format!("{:.*}{}", 1, total_rx_converted_result.0, total_rx_converted_result.1)
|
||||
format!(
|
||||
"{:.*}{}",
|
||||
1, total_rx_converted_result.0, total_rx_converted_result.1
|
||||
)
|
||||
} else {
|
||||
"N/A".to_string()
|
||||
};
|
||||
|
@ -350,7 +411,10 @@ pub fn convert_network_data_points(network_data: &[data_collection::network::Net
|
|||
}
|
||||
let tx_display = format!("{:.*}{}", 1, tx_converted_result.0, tx_converted_result.1);
|
||||
let total_tx_display = if cfg!(not(target_os = "windows")) {
|
||||
format!("{:.*}{}", 1, total_tx_converted_result.0, total_tx_converted_result.1)
|
||||
format!(
|
||||
"{:.*}{}",
|
||||
1, total_tx_converted_result.0, total_tx_converted_result.1
|
||||
)
|
||||
} else {
|
||||
"N/A".to_string()
|
||||
};
|
||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -8,7 +8,10 @@ extern crate failure;
|
|||
extern crate lazy_static;
|
||||
|
||||
use crossterm::{
|
||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent},
|
||||
event::{
|
||||
self, DisableMouseCapture, EnableMouseCapture, Event as CEvent, KeyCode, KeyEvent,
|
||||
KeyModifiers, MouseEvent,
|
||||
},
|
||||
execute,
|
||||
terminal::LeaveAlternateScreen,
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen},
|
||||
|
@ -183,7 +186,8 @@ fn main() -> error::Result<()> {
|
|||
}
|
||||
}
|
||||
futures::executor::block_on(data_state.update_data());
|
||||
tx.send(Event::Update(Box::from(data_state.data.clone()))).unwrap();
|
||||
tx.send(Event::Update(Box::from(data_state.data.clone())))
|
||||
.unwrap();
|
||||
|
||||
if first_run {
|
||||
// Fix for if you set a really long time for update periods (and just gives a faster first value)
|
||||
|
@ -285,10 +289,13 @@ fn main() -> error::Result<()> {
|
|||
// pulls double duty by allowing us to combine entries AND it sorts!
|
||||
|
||||
// Fields for tuple: CPU%, MEM%, PID_VEC
|
||||
let mut process_map: BTreeMap<String, (f64, f64, Vec<u32>)> = BTreeMap::new();
|
||||
let mut process_map: BTreeMap<String, (f64, f64, Vec<u32>)> =
|
||||
BTreeMap::new();
|
||||
for process in &app.data.list_of_processes {
|
||||
if let Some(mem_usage) = process.mem_usage_percent {
|
||||
let entry_val = process_map.entry(process.command.clone()).or_insert((0.0, 0.0, vec![]));
|
||||
let entry_val = process_map
|
||||
.entry(process.command.clone())
|
||||
.or_insert((0.0, 0.0, vec![]));
|
||||
|
||||
entry_val.0 += process.cpu_usage_percent;
|
||||
entry_val.1 += mem_usage;
|
||||
|
@ -327,12 +334,14 @@ fn main() -> error::Result<()> {
|
|||
app.canvas_data.total_rx_display = network_data.total_rx_display;
|
||||
app.canvas_data.total_tx_display = network_data.total_tx_display;
|
||||
app.canvas_data.disk_data = update_disk_row(&app.data);
|
||||
app.canvas_data.temp_sensor_data = update_temp_row(&app.data, &app.temperature_type);
|
||||
app.canvas_data.temp_sensor_data =
|
||||
update_temp_row(&app.data, &app.temperature_type);
|
||||
app.canvas_data.process_data = update_process_row(&app.data);
|
||||
app.canvas_data.mem_data = update_mem_data_points(&app.data);
|
||||
app.canvas_data.memory_labels = update_mem_data_values(&app.data);
|
||||
app.canvas_data.swap_data = update_swap_data_points(&app.data);
|
||||
app.canvas_data.cpu_data = update_cpu_data_points(app.show_average_cpu, &app.data);
|
||||
app.canvas_data.cpu_data =
|
||||
update_cpu_data_points(app.show_average_cpu, &app.data);
|
||||
//debug!("Update event complete.");
|
||||
}
|
||||
}
|
||||
|
@ -350,7 +359,9 @@ fn main() -> error::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn cleanup(terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>) -> error::Result<()> {
|
||||
fn cleanup(
|
||||
terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>,
|
||||
) -> error::Result<()> {
|
||||
disable_raw_mode()?;
|
||||
execute!(terminal.backend_mut(), DisableMouseCapture)?;
|
||||
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
|
||||
|
|
|
@ -20,7 +20,10 @@ pub enum BottomError {
|
|||
/// An error when the heim library encounters a problem.
|
||||
///
|
||||
/// The data provided is the error found.
|
||||
#[fail(display = "ERROR: Invalid error during data collection due to Heim: {}", message)]
|
||||
#[fail(
|
||||
display = "ERROR: Invalid error during data collection due to Heim: {}",
|
||||
message
|
||||
)]
|
||||
InvalidHeim { message: String },
|
||||
/// An error when the Crossterm library encounters a problem.
|
||||
///
|
||||
|
@ -41,25 +44,33 @@ pub enum BottomError {
|
|||
|
||||
impl From<std::io::Error> for BottomError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
BottomError::InvalidIO { message: err.to_string() }
|
||||
BottomError::InvalidIO {
|
||||
message: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<heim::Error> for BottomError {
|
||||
fn from(err: heim::Error) -> Self {
|
||||
BottomError::InvalidHeim { message: err.to_string() }
|
||||
BottomError::InvalidHeim {
|
||||
message: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crossterm::ErrorKind> for BottomError {
|
||||
fn from(err: crossterm::ErrorKind) -> Self {
|
||||
BottomError::CrosstermError { message: err.to_string() }
|
||||
BottomError::CrosstermError {
|
||||
message: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::num::ParseIntError> for BottomError {
|
||||
fn from(err: std::num::ParseIntError) -> Self {
|
||||
BottomError::InvalidArg { message: err.to_string() }
|
||||
BottomError::InvalidArg {
|
||||
message: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,6 +82,8 @@ impl From<std::string::String> for BottomError {
|
|||
|
||||
impl From<fern::InitError> for BottomError {
|
||||
fn from(err: fern::InitError) -> Self {
|
||||
BottomError::FernError { message: err.to_string() }
|
||||
BottomError::FernError {
|
||||
message: err.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,14 @@ pub fn float_max(a: f32, b: f32) -> f32 {
|
|||
/// This only supports up to a tebibyte.
|
||||
pub fn get_exact_byte_values(bytes: u64, spacing: bool) -> (f64, String) {
|
||||
match bytes {
|
||||
b if b < 1024 => (bytes as f64, if spacing { " B".to_string() } else { "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()),
|
||||
|
@ -38,7 +45,14 @@ pub fn get_exact_byte_values(bytes: u64, spacing: bool) -> (f64, String) {
|
|||
/// 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, spacing: bool) -> (f64, String) {
|
||||
match bytes {
|
||||
b if b < 1000 => (bytes as f64, if spacing { " B".to_string() } else { "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…
Reference in New Issue