Added some more support for windows.
This commit is contained in:
parent
cb9ec2cdca
commit
bc3169a4df
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bottom"
|
||||
version = "0.1.0-alpha.2"
|
||||
version = "0.1.0-alpha.3"
|
||||
authors = ["Clement Tsang <clementjhtsang@gmail.com>"]
|
||||
edition = "2018"
|
||||
repository = "https://github.com/ClementTsang/bottom"
|
||||
|
@ -24,6 +24,7 @@ futures-util = "0.2.1"
|
|||
heim = "0.0.7"
|
||||
heim-common = "0.0.7"
|
||||
log = "0.4"
|
||||
rayon = "1.2"
|
||||
sysinfo = "0.9.4"
|
||||
tokio = "0.2.0-alpha.4"
|
||||
|
||||
|
|
|
@ -100,7 +100,10 @@ impl DataState {
|
|||
set_if_valid(&disks::get_disk_usage_list().await, &mut self.data.list_of_disks);
|
||||
push_if_valid(&disks::get_io_usage_list(false).await, &mut self.data.list_of_io);
|
||||
//push_if_valid(&disks::get_io_usage_list(true).await, &mut self.data.list_of_physical_io); // Removed, seems irrelevant for now...
|
||||
set_if_valid(&temperature::get_temperature_data(&self.temperature_type).await, &mut self.data.list_of_temperature_sensor);
|
||||
set_if_valid(
|
||||
&temperature::get_temperature_data(&self.sys, &self.temperature_type).await,
|
||||
&mut self.data.list_of_temperature_sensor,
|
||||
);
|
||||
|
||||
if self.first_run {
|
||||
self.data = Data::default();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use heim_common::{prelude::StreamExt, units::thermodynamic_temperature};
|
||||
use sysinfo::{ComponentExt, System, SystemExt};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TempData {
|
||||
|
@ -19,18 +20,34 @@ impl Default for TemperatureType {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn get_temperature_data(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();
|
||||
|
||||
let mut sensor_data = heim::sensors::temperatures();
|
||||
while let Some(sensor) = sensor_data.next().await {
|
||||
if let Ok(sensor) = sensor {
|
||||
if cfg!(target_os = "linux") {
|
||||
let mut sensor_data = heim::sensors::temperatures();
|
||||
while let Some(sensor) = sensor_data.next().await {
|
||||
if let Ok(sensor) = sensor {
|
||||
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>(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else if cfg!(target_os = "windows") {
|
||||
let sensor_data = sys.get_components_list();
|
||||
debug!("TEMPS: {:?}", sensor_data);
|
||||
for component in sensor_data {
|
||||
temperature_vec.push(TempData {
|
||||
component_name : Box::from(sensor.unit()),
|
||||
component_name : Box::from(component.get_label()),
|
||||
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 => component.get_temperature(),
|
||||
TemperatureType::Kelvin => component.get_temperature() + 273.15,
|
||||
TemperatureType::Fahrenheit => (component.get_temperature() * (9.0 / 5.0)) + 32.0,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,16 +4,21 @@ use constants::*;
|
|||
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();
|
||||
|
||||
for sensor in &app_data.list_of_temperature_sensor {
|
||||
sensor_vector.push(vec![
|
||||
sensor.component_name.to_string(),
|
||||
(sensor.temperature.ceil() as u64).to_string()
|
||||
+ match temp_type {
|
||||
data_collection::temperature::TemperatureType::Celsius => "C",
|
||||
data_collection::temperature::TemperatureType::Kelvin => "K",
|
||||
data_collection::temperature::TemperatureType::Fahrenheit => "F",
|
||||
},
|
||||
]);
|
||||
if (&app_data.list_of_temperature_sensor).is_empty() {
|
||||
sensor_vector.push(vec!["None Found".to_string(), "".to_string()])
|
||||
}
|
||||
else {
|
||||
for sensor in &app_data.list_of_temperature_sensor {
|
||||
sensor_vector.push(vec![
|
||||
sensor.component_name.to_string(),
|
||||
(sensor.temperature.ceil() as u64).to_string()
|
||||
+ match temp_type {
|
||||
data_collection::temperature::TemperatureType::Celsius => "C",
|
||||
data_collection::temperature::TemperatureType::Kelvin => "K",
|
||||
data_collection::temperature::TemperatureType::Fahrenheit => "F",
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
sensor_vector
|
||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -7,8 +7,13 @@ extern crate clap;
|
|||
#[macro_use]
|
||||
extern crate failure;
|
||||
|
||||
use crossterm::{input, AlternateScreen, InputEvent, KeyEvent, MouseButton, MouseEvent};
|
||||
use std::{sync::mpsc, thread, time::Duration};
|
||||
use crossterm::{input, queue, AlternateScreen, InputEvent, KeyEvent, MouseButton, MouseEvent};
|
||||
use std::{
|
||||
io::{stdout, Write},
|
||||
sync::mpsc,
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use tui_temp_fork::{backend::CrosstermBackend, Terminal};
|
||||
|
||||
pub mod app;
|
||||
|
@ -84,9 +89,18 @@ fn main() -> error::Result<()> {
|
|||
|
||||
// Set up up tui and crossterm
|
||||
let screen = AlternateScreen::to_alternate(true)?;
|
||||
let stdout = std::io::stdout();
|
||||
let mut stdout = stdout();
|
||||
|
||||
if cfg!(target_os = "windows") {
|
||||
screen.to_main()?;
|
||||
queue!(stdout, crossterm::Clear(crossterm::ClearType::All), crossterm::BlinkOff)?;
|
||||
|
||||
stdout.flush()?;
|
||||
}
|
||||
|
||||
let backend = CrosstermBackend::with_alternate_screen(stdout, screen)?;
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
terminal.set_cursor(0, 0)?;
|
||||
terminal.hide_cursor()?;
|
||||
terminal.clear()?;
|
||||
|
||||
|
@ -96,7 +110,10 @@ fn main() -> error::Result<()> {
|
|||
let tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
let input = input();
|
||||
input.enable_mouse_mode().unwrap();
|
||||
// TODO: Temp!
|
||||
if !(cfg!(target_os = "windows")) {
|
||||
input.enable_mouse_mode().unwrap(); // TODO: I think this is broken on windows...
|
||||
}
|
||||
let reader = input.read_sync();
|
||||
for event in reader {
|
||||
match event {
|
||||
|
|
Loading…
Reference in New Issue