Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tui version... legends aren't showing up yet, will have to for… #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ path = "src/main.rs"
[dependencies]
chrono = "0.4.9"
clap = "2.33.0"
crossterm = "^0.10"
crossterm = "0.13"
failure = "0.1.5"
futures-preview = "0.3.0-alpha.18"
fern = "0.5"
Expand All @@ -32,10 +32,8 @@ sysinfo = "0.9.4"
tokio = "0.2.0-alpha.4"
winapi = "0.3.8"

[dependencies.tui-temp-fork]
#git = "https://github.com/ClementTsang/tui-rs"
path = "../tui-rs"
version = "0.6"
[dependencies.tui]
version = "0.7"
default-features = false
features = ['crossterm']

Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
max_width = 150
newline_style = "Unix"
reorder_imports = true
control_brace_style = "ClosingNextLine"
fn_args_layout = "Compressed"
Expand Down
88 changes: 43 additions & 45 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,55 @@ pub enum ScrollDirection {
}

pub struct App {
pub process_sorting_type : processes::ProcessSorting,
pub process_sorting_reverse : bool,
pub to_be_resorted : bool,
pub currently_selected_process_position : i64,
pub currently_selected_disk_position : i64,
pub currently_selected_temperature_position : i64,
pub temperature_type : temperature::TemperatureType,
pub update_rate_in_milliseconds : u64,
pub show_average_cpu : bool,
pub current_application_position : ApplicationPosition,
pub current_zoom_level_percent : f64, // Make at most 200, least 50?
pub data : data_collection::Data,
pub scroll_direction : ScrollDirection,
pub previous_disk_position : i64,
pub previous_temp_position : i64,
pub previous_process_position : i64,
awaiting_second_d : bool,
pub use_dot : bool,
pub show_help : bool,
pub is_frozen : bool,
pub process_sorting_type: processes::ProcessSorting,
pub process_sorting_reverse: bool,
pub to_be_resorted: bool,
pub currently_selected_process_position: i64,
pub currently_selected_disk_position: i64,
pub currently_selected_temperature_position: i64,
pub temperature_type: temperature::TemperatureType,
pub update_rate_in_milliseconds: u64,
pub show_average_cpu: bool,
pub current_application_position: ApplicationPosition,
pub current_zoom_level_percent: f64, // Make at most 200, least 50?
pub data: data_collection::Data,
pub scroll_direction: ScrollDirection,
pub previous_disk_position: i64,
pub previous_temp_position: i64,
pub previous_process_position: i64,
awaiting_second_d: bool,
pub use_dot: bool,
pub show_help: bool,
pub is_frozen: bool,
}

impl App {
pub fn new(show_average_cpu : bool, temperature_type : temperature::TemperatureType, update_rate_in_milliseconds : u64, use_dot : bool) -> App {
pub fn new(show_average_cpu: bool, temperature_type: temperature::TemperatureType, update_rate_in_milliseconds: u64, use_dot: bool) -> App {
App {
process_sorting_type : processes::ProcessSorting::CPU,
process_sorting_reverse : true,
to_be_resorted : false,
currently_selected_process_position : 0,
currently_selected_disk_position : 0,
currently_selected_temperature_position : 0,
process_sorting_type: processes::ProcessSorting::CPU,
process_sorting_reverse: true,
to_be_resorted: false,
currently_selected_process_position: 0,
currently_selected_disk_position: 0,
currently_selected_temperature_position: 0,
temperature_type,
update_rate_in_milliseconds,
show_average_cpu,
current_application_position : ApplicationPosition::PROCESS,
current_zoom_level_percent : 100.0,
data : data_collection::Data::default(),
scroll_direction : ScrollDirection::DOWN,
previous_process_position : 0,
previous_disk_position : 0,
previous_temp_position : 0,
awaiting_second_d : false,
current_application_position: ApplicationPosition::PROCESS,
current_zoom_level_percent: 100.0,
data: data_collection::Data::default(),
scroll_direction: ScrollDirection::DOWN,
previous_process_position: 0,
previous_disk_position: 0,
previous_temp_position: 0,
awaiting_second_d: false,
use_dot,
show_help : false,
is_frozen : false,
show_help: false,
is_frozen: false,
}
}

pub fn on_enter(&mut self) {
}
pub fn on_enter(&mut self) {}

pub fn on_esc(&mut self) {
if self.show_help {
Expand All @@ -79,15 +78,14 @@ impl App {
}

// TODO: How should we make it for process panel specific hotkeys? Only if we're on process panel? Or what?
pub fn on_key(&mut self, c : char) {
pub fn on_key(&mut self, c: char) {
if !self.show_help {
match c {
'd' => {
if self.awaiting_second_d {
self.awaiting_second_d = false;
self.kill_highlighted_process().unwrap_or(());
}
else {
} else {
self.awaiting_second_d = true;
}
}
Expand Down Expand Up @@ -223,23 +221,23 @@ impl App {
self.scroll_direction = ScrollDirection::DOWN;
}

fn change_process_position(&mut self, num_to_change_by : i64) {
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;
}
}

fn change_temp_position(&mut self, num_to_change_by : i64) {
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;
}
}

fn change_disk_position(&mut self, num_to_change_by : i64) {
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
{
Expand Down
62 changes: 31 additions & 31 deletions src/app/data_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,61 @@ pub mod network;
pub mod processes;
pub mod temperature;

fn set_if_valid<T : std::clone::Clone>(result : &Result<T, crate::utils::error::RustopError>, value_to_set : &mut T) {
fn set_if_valid<T: std::clone::Clone>(result: &Result<T, crate::utils::error::RustopError>, value_to_set: &mut T) {
if let Ok(result) = result {
*value_to_set = (*result).clone();
}
}

fn push_if_valid<T : std::clone::Clone>(result : &Result<T, crate::utils::error::RustopError>, vector_to_push : &mut Vec<T>) {
fn push_if_valid<T: std::clone::Clone>(result: &Result<T, crate::utils::error::RustopError>, vector_to_push: &mut Vec<T>) {
if let Ok(result) = result {
vector_to_push.push(result.clone());
}
}

#[derive(Default, Clone)]
pub struct Data {
pub list_of_cpu_packages : Vec<cpu::CPUPackage>,
pub list_of_io : Vec<disks::IOPackage>,
pub list_of_physical_io : Vec<disks::IOPackage>,
pub memory : Vec<mem::MemData>,
pub swap : Vec<mem::MemData>,
pub list_of_temperature_sensor : Vec<temperature::TempData>,
pub network : Vec<network::NetworkData>,
pub list_of_processes : Vec<processes::ProcessData>, // Only need to keep a list of processes...
pub list_of_disks : Vec<disks::DiskData>, // Only need to keep a list of disks and their data
pub list_of_cpu_packages: Vec<cpu::CPUPackage>,
pub list_of_io: Vec<disks::IOPackage>,
pub list_of_physical_io: Vec<disks::IOPackage>,
pub memory: Vec<mem::MemData>,
pub swap: Vec<mem::MemData>,
pub list_of_temperature_sensor: Vec<temperature::TempData>,
pub network: Vec<network::NetworkData>,
pub list_of_processes: Vec<processes::ProcessData>, // Only need to keep a list of processes...
pub list_of_disks: Vec<disks::DiskData>, // Only need to keep a list of disks and their data
}

pub struct DataState {
pub data : Data,
first_run : bool,
sys : System,
stale_max_seconds : u64,
prev_pid_stats : HashMap<String, (f64, Instant)>,
prev_idle : f64,
prev_non_idle : f64,
temperature_type : temperature::TemperatureType,
last_clean : Instant, // Last time stale data was cleared
pub data: Data,
first_run: bool,
sys: System,
stale_max_seconds: u64,
prev_pid_stats: HashMap<String, (f64, Instant)>,
prev_idle: f64,
prev_non_idle: f64,
temperature_type: temperature::TemperatureType,
last_clean: Instant, // Last time stale data was cleared
}

impl Default for DataState {
fn default() -> Self {
DataState {
data : Data::default(),
first_run : true,
sys : System::new(),
stale_max_seconds : constants::STALE_MAX_MILLISECONDS / 1000,
prev_pid_stats : HashMap::new(),
prev_idle : 0_f64,
prev_non_idle : 0_f64,
temperature_type : temperature::TemperatureType::Celsius,
last_clean : Instant::now(),
data: Data::default(),
first_run: true,
sys: System::new(),
stale_max_seconds: constants::STALE_MAX_MILLISECONDS / 1000,
prev_pid_stats: HashMap::new(),
prev_idle: 0_f64,
prev_non_idle: 0_f64,
temperature_type: temperature::TemperatureType::Celsius,
last_clean: Instant::now(),
}
}
}

impl DataState {
pub fn set_temperature_type(&mut self, temperature_type : temperature::TemperatureType) {
pub fn set_temperature_type(&mut self, temperature_type: temperature::TemperatureType) {
self.temperature_type = temperature_type;
}

Expand Down Expand Up @@ -113,7 +113,7 @@ impl DataState {
let current_instant = std::time::Instant::now();

if current_instant.duration_since(self.last_clean).as_secs() > self.stale_max_seconds {
let stale_list : Vec<_> = self
let stale_list: Vec<_> = self
.prev_pid_stats
.iter()
.filter(|&(_, &v)| current_instant.duration_since(v.1).as_secs() > self.stale_max_seconds)
Expand Down
16 changes: 8 additions & 8 deletions src/app/data_collection/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ use sysinfo::{ProcessorExt, System, SystemExt};

#[derive(Clone)]
pub struct CPUData {
pub cpu_name : Box<str>,
pub cpu_usage : f64,
pub cpu_name: Box<str>,
pub cpu_usage: f64,
}

#[derive(Clone)]
pub struct CPUPackage {
pub cpu_vec : Vec<CPUData>,
pub instant : Instant,
pub cpu_vec: Vec<CPUData>,
pub instant: Instant,
}

pub fn get_cpu_data_list(sys : &System) -> crate::utils::error::Result<CPUPackage> {
pub fn get_cpu_data_list(sys: &System) -> crate::utils::error::Result<CPUPackage> {
let cpu_data = sys.get_processor_list();
let mut cpu_vec = Vec::new();

for cpu in cpu_data {
cpu_vec.push(CPUData {
cpu_name : Box::from(cpu.get_name()),
cpu_usage : f64::from(cpu.get_cpu_usage()) * 100_f64,
cpu_name: Box::from(cpu.get_name()),
cpu_usage: f64::from(cpu.get_cpu_usage()) * 100_f64,
})
}

Ok(CPUPackage {
cpu_vec,
instant : Instant::now(),
instant: Instant::now(),
})
}
18 changes: 9 additions & 9 deletions src/app/data_collection/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ use std::time::Instant;

#[derive(Clone)]
pub struct MemData {
pub mem_total_in_mb : u64,
pub mem_used_in_mb : u64,
pub instant : Instant,
pub mem_total_in_mb: u64,
pub mem_used_in_mb: u64,
pub instant: Instant,
}

pub async fn get_mem_data_list() -> crate::utils::error::Result<MemData> {
let memory = heim::memory::memory().await?;

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>(),
instant : Instant::now(),
mem_total_in_mb: memory.total().get::<information::megabyte>(),
mem_used_in_mb: memory.total().get::<information::megabyte>() - memory.available().get::<information::megabyte>(),
instant: Instant::now(),
})
}

pub async fn get_swap_data_list() -> crate::utils::error::Result<MemData> {
let memory = heim::memory::swap().await?;

Ok(MemData {
mem_total_in_mb : memory.total().get::<information::megabyte>(),
mem_used_in_mb : memory.used().get::<information::megabyte>(),
instant : Instant::now(),
mem_total_in_mb: memory.total().get::<information::megabyte>(),
mem_used_in_mb: memory.used().get::<information::megabyte>(),
instant: Instant::now(),
})
}
Loading