mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-25 13:40:20 +00:00
Added temp setting to app, need to add to data collection. Also refactoring again.
This commit is contained in:
parent
ae6cd3aa77
commit
86eb14f620
4 changed files with 33 additions and 17 deletions
|
@ -4,6 +4,14 @@ use data_collection::{cpu, disks, mem, network, processes, temperature};
|
|||
use std::collections::HashMap;
|
||||
use sysinfo::{System, SystemExt};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone)]
|
||||
pub enum TemperatureType {
|
||||
Celsius,
|
||||
Kelvin,
|
||||
Fahrenheit,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct App<'a> {
|
||||
title : &'a str,
|
||||
|
@ -12,6 +20,7 @@ pub struct App<'a> {
|
|||
pub process_sorting_reverse : bool,
|
||||
pub to_be_resorted : bool,
|
||||
pub current_selected_process_position : u64,
|
||||
pub temperature_type : TemperatureType,
|
||||
}
|
||||
|
||||
fn set_if_valid<T : std::clone::Clone>(result : &Result<T, heim::Error>, value_to_set : &mut T) {
|
||||
|
@ -46,6 +55,7 @@ pub struct DataState {
|
|||
prev_pid_stats : HashMap<String, f64>, // TODO: Purge list?
|
||||
prev_idle : f64,
|
||||
prev_non_idle : f64,
|
||||
temperature_type : TemperatureType,
|
||||
}
|
||||
|
||||
impl Default for DataState {
|
||||
|
@ -57,6 +67,7 @@ impl Default for DataState {
|
|||
prev_pid_stats : HashMap::new(),
|
||||
prev_idle : 0_f64,
|
||||
prev_non_idle : 0_f64,
|
||||
temperature_type : TemperatureType::Celsius,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +77,10 @@ impl DataState {
|
|||
self.stale_max_seconds = stale_max_seconds;
|
||||
}
|
||||
|
||||
pub fn set_temperature_type(&mut self, temperature_type : TemperatureType) {
|
||||
self.temperature_type = temperature_type;
|
||||
}
|
||||
|
||||
pub fn init(&mut self) {
|
||||
self.sys.refresh_system();
|
||||
self.sys.refresh_network();
|
||||
|
@ -157,6 +172,7 @@ impl<'a> App<'a> {
|
|||
process_sorting_reverse : true,
|
||||
to_be_resorted : false,
|
||||
current_selected_process_position : 0,
|
||||
temperature_type : TemperatureType::Celsius,
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,8 @@ use tui::{
|
|||
Terminal,
|
||||
};
|
||||
|
||||
const COLOUR_LIST : [Color; 6] = [Color::LightCyan, Color::LightMagenta, Color::LightRed, Color::LightGreen, Color::LightYellow, Color::LightBlue];
|
||||
const COLOUR_LIST : [Color; 6] = [Color::LightRed, Color::LightGreen, Color::LightYellow, Color::LightBlue, Color::LightCyan, Color::LightMagenta];
|
||||
const TEXT_COLOUR : Color = Color::Green;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CanvasData {
|
||||
|
@ -20,21 +21,11 @@ pub struct CanvasData {
|
|||
|
||||
// TODO: Change the error
|
||||
pub fn draw_data<B : tui::backend::Backend>(terminal : &mut Terminal<B>, canvas_data : &CanvasData) -> Result<(), io::Error> {
|
||||
let temperature_rows = canvas_data.temp_sensor_data.iter().map(|sensor| {
|
||||
Row::StyledData(
|
||||
sensor.iter(), // TODO: Change this based on temperature type
|
||||
Style::default().fg(Color::White),
|
||||
)
|
||||
});
|
||||
let temperature_rows = canvas_data.temp_sensor_data.iter().map(|sensor| Row::StyledData(sensor.iter(), Style::default().fg(TEXT_COLOUR)));
|
||||
|
||||
let disk_rows = canvas_data.disk_data.iter().map(|disk| {
|
||||
Row::StyledData(
|
||||
disk.iter(), // TODO: Change this based on temperature type
|
||||
Style::default().fg(Color::White),
|
||||
)
|
||||
});
|
||||
let disk_rows = canvas_data.disk_data.iter().map(|disk| Row::StyledData(disk.iter(), Style::default().fg(TEXT_COLOUR)));
|
||||
|
||||
let process_rows = canvas_data.process_data.iter().map(|process| Row::StyledData(process.iter(), Style::default().fg(Color::White)));
|
||||
let process_rows = canvas_data.process_data.iter().map(|process| Row::StyledData(process.iter(), Style::default().fg(TEXT_COLOUR)));
|
||||
|
||||
// TODO: Convert this into a separate func!
|
||||
terminal.draw(|mut f| {
|
15
src/main.rs
15
src/main.rs
|
@ -53,6 +53,7 @@ async fn main() -> Result<(), io::Error> {
|
|||
let mut data_state = app::DataState::default();
|
||||
data_state.init();
|
||||
data_state.set_stale_max_seconds(STALE_MAX_SECONDS);
|
||||
data_state.set_temperature_type(app.temperature_type.clone());
|
||||
{
|
||||
let tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
|
@ -101,7 +102,7 @@ async fn main() -> Result<(), io::Error> {
|
|||
|
||||
// Convert all data into tui components
|
||||
canvas_data.disk_data = update_disk_row(&app_data);
|
||||
canvas_data.temp_sensor_data = update_temp_row(&app_data);
|
||||
canvas_data.temp_sensor_data = update_temp_row(&app_data, &app.temperature_type);
|
||||
canvas_data.process_data = update_process_row(&app_data);
|
||||
canvas_data.mem_data = update_mem_data_points(&app_data);
|
||||
canvas_data.swap_data = update_swap_data_points(&app_data);
|
||||
|
@ -121,11 +122,19 @@ async fn main() -> Result<(), io::Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn update_temp_row(app_data : &app::Data) -> Vec<Vec<String>> {
|
||||
fn update_temp_row(app_data : &app::Data, temp_type : &app::TemperatureType) -> Vec<Vec<String>> {
|
||||
let mut sensor_vector : Vec<Vec<String>> = Vec::new();
|
||||
|
||||
for sensor in &app_data.list_of_temperature_sensor {
|
||||
sensor_vector.push(vec![sensor.component_name.to_string(), sensor.temperature.to_string() + "C"]);
|
||||
sensor_vector.push(vec![
|
||||
sensor.component_name.to_string(),
|
||||
sensor.temperature.to_string()
|
||||
+ match temp_type {
|
||||
app::TemperatureType::Celsius => "C",
|
||||
app::TemperatureType::Kelvin => "K",
|
||||
app::TemperatureType::Fahrenheit => "F",
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
sensor_vector
|
||||
|
|
Loading…
Reference in a new issue