Update tui version... legends aren't showing up yet, will have to fork again.

This commit is contained in:
ClementTsang 2019-12-06 00:57:04 -05:00
parent 078cca4100
commit e7477ce517
13 changed files with 257 additions and 313 deletions

View file

@ -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"
@ -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']

View file

@ -1,4 +1,5 @@
max_width = 150
newline_style = "Unix"
reorder_imports = true
control_brace_style = "ClosingNextLine"
fn_args_layout = "Compressed"

View file

@ -69,8 +69,7 @@ impl App {
}
}
pub fn on_enter(&mut self) {
}
pub fn on_enter(&mut self) {}
pub fn on_esc(&mut self) {
if self.show_help {
@ -86,8 +85,7 @@ impl App {
if self.awaiting_second_d {
self.awaiting_second_d = false;
self.kill_highlighted_process().unwrap_or(());
}
else {
} else {
self.awaiting_second_d = true;
}
}

View file

@ -69,8 +69,7 @@ fn vangelis_cpu_usage_calculation(prev_idle : &mut f64, prev_non_idle : &mut f64
let result = if total_delta - idle_delta != 0_f64 {
total_delta - idle_delta
}
else {
} else {
1_f64
};
@ -83,20 +82,16 @@ fn get_ordering<T : std::cmp::PartialOrd>(a_val : T, b_val : T, reverse_order :
if a_val > b_val {
if reverse_order {
std::cmp::Ordering::Less
}
else {
} else {
std::cmp::Ordering::Greater
}
}
else if a_val < b_val {
} else if a_val < b_val {
if reverse_order {
std::cmp::Ordering::Greater
}
else {
} else {
std::cmp::Ordering::Less
}
}
else {
} else {
std::cmp::Ordering::Equal
}
}
@ -118,14 +113,11 @@ 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)>,
) -> std::io::Result<f64> {
fn linux_cpu_usage(pid: u32, cpu_usage: f64, cpu_percentage: f64, previous_pid_stats: &mut HashMap<String, (f64, Instant)>) -> 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
}
else {
} else {
0_f64
};
let after_proc_val = get_process_cpu_stats(pid)?;
@ -192,8 +184,7 @@ pub async fn get_sorted_processes_list(
}
}
}
}
else if cfg!(target_os = "windows") {
} else if cfg!(target_os = "windows") {
// Windows
let process_hashmap = sys.get_process_list();
@ -206,12 +197,10 @@ pub async fn get_sorted_processes_list(
cpu_usage_percent: f64::from(process_val.cpu_usage()),
});
}
}
else if cfg!(target_os = "macos") {
} else if cfg!(target_os = "macos") {
// TODO: macOS
debug!("Mac");
}
else {
} else {
// TODO: Others?
debug!("Else");
// Solaris: https://stackoverflow.com/a/4453581

View file

@ -37,19 +37,16 @@ pub fn kill_process_given_pid(pid : u64) -> crate::utils::error::Result<()> {
if cfg!(target_os = "linux") {
// Linux
Command::new("kill").arg(pid.to_string()).output()?;
}
else if cfg!(target_os = "windows") {
} else if cfg!(target_os = "windows") {
#[cfg(target_os = "windows")]
let process = Process::open(pid as DWORD)?;
#[cfg(target_os = "windows")]
process.kill()?;
}
else if cfg!(target_os = "macos") {
} else if cfg!(target_os = "macos") {
// TODO: macOS
// See how sysinfo does it... https://docs.rs/sysinfo/0.9.5/sysinfo/trait.ProcessExt.html
debug!("Sorry, macOS support is not implemented yet!");
}
else {
} else {
// TODO: Others?
debug!("Sorry, other support this is not implemented yet!");
}

View file

@ -1,5 +1,5 @@
use crate::{app, constants, utils::error};
use tui_temp_fork::{
use tui::{
backend,
layout::{Alignment, Constraint, Direction, Layout},
style::{Color, Modifier, Style},
@ -80,8 +80,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.alignment(Alignment::Left)
.wrap(true)
.render(&mut f, middle_dialog_chunk[1]);
}
else {
} else {
let vertical_chunks = Layout::default()
.direction(Direction::Vertical)
.margin(1)
@ -125,8 +124,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if i == 0 {
// Skip, we want to render the average cpu last!
continue;
}
else {
} else {
avg_cpu_exist_offset = 1;
}
}
@ -247,8 +245,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if disk_counter == app_state.currently_selected_temperature_position - start_position {
disk_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan)
}
else {
} else {
if disk_counter >= 0 {
disk_counter += 1;
}
@ -292,8 +289,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if disk_counter == app_state.currently_selected_disk_position - start_position {
disk_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan)
}
else {
} else {
if disk_counter >= 0 {
disk_counter += 1;
}
@ -393,8 +389,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
if process_counter == app_state.currently_selected_process_position - start_position {
process_counter = -1;
Style::default().fg(Color::Black).bg(Color::Cyan)
}
else {
} else {
if process_counter >= 0 {
process_counter += 1;
}
@ -412,8 +407,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
let direction_val = if app_state.process_sorting_reverse {
"".to_string()
}
else {
} else {
"".to_string()
};
@ -459,11 +453,9 @@ fn get_start_position(
app::ScrollDirection::DOWN => {
if *currently_selected_position < num_rows {
0
}
else if *currently_selected_position - num_rows < *previous_position {
} else if *currently_selected_position - num_rows < *previous_position {
*previous_position
}
else {
} else {
*previous_position = *currently_selected_position - num_rows + 1;
*previous_position
}
@ -472,8 +464,7 @@ fn get_start_position(
if *currently_selected_position == *previous_position - 1 {
*previous_position = if *previous_position > 0 { *previous_position - 1 } else { 0 };
*previous_position
}
else {
} else {
*previous_position
}
}

View file

@ -6,8 +6,7 @@ pub fn update_temp_row(app_data : &data_collection::Data, temp_type : &data_coll
if (&app_data.list_of_temperature_sensor).is_empty() {
sensor_vector.push(vec!["No Sensors Found".to_string(), "".to_string()])
}
else {
} else {
for sensor in &app_data.list_of_temperature_sensor {
sensor_vector.push(vec![
sensor.component_name.to_string(),
@ -44,37 +43,29 @@ pub fn update_disk_row(app_data : &data_collection::Data) -> Vec<Vec<String>> {
(
if read_bytes_per_sec < 1024 {
format!("{}B", read_bytes_per_sec)
}
else if read_bytes_per_sec < 1024 * 1024 {
} else if read_bytes_per_sec < 1024 * 1024 {
format!("{}KB", read_bytes_per_sec / 1024)
}
else {
} else {
format!("{}MB", read_bytes_per_sec / 1024 / 1024)
},
if write_bytes_per_sec < 1024 {
format!("{}B", write_bytes_per_sec)
}
else if write_bytes_per_sec < 1024 * 1024 {
} else if write_bytes_per_sec < 1024 * 1024 {
format!("{}KB", write_bytes_per_sec / 1024)
}
else {
} else {
format!("{}MB", write_bytes_per_sec / 1024 / 1024)
},
)
}
else {
} else {
("0B".to_string(), "0B".to_string())
}
}
else {
} else {
("0B".to_string(), "0B".to_string())
}
}
else {
} else {
("0B".to_string(), "0B".to_string())
}
}
else {
} else {
("0B".to_string(), "0B".to_string())
};
disk_vector.push(vec![
@ -83,14 +74,12 @@ pub fn update_disk_row(app_data : &data_collection::Data) -> Vec<Vec<String>> {
format!("{:.0}%", disk.used_space as f64 / disk.total_space as f64 * 100_f64),
if disk.free_space < 1024 {
disk.free_space.to_string() + "MB"
}
else {
} else {
(disk.free_space / 1024).to_string() + "GB"
},
if disk.total_space < 1024 {
disk.total_space.to_string() + "MB"
}
else {
} else {
(disk.total_space / 1024).to_string() + "GB"
},
io_activity.0,
@ -113,16 +102,13 @@ pub fn update_process_row(app_data : &data_collection::Data) -> Vec<Vec<String>>
"{:.1}%",
if let Some(mem_usage) = process.mem_usage_percent {
mem_usage
}
else if let Some(mem_usage_kb) = process.mem_usage_kb {
} else if let Some(mem_usage_kb) = process.mem_usage_kb {
if let Some(mem_data) = app_data.memory.last() {
(mem_usage_kb / 1024) as f64 / mem_data.mem_total_in_mb as f64 * 100_f64
}
else {
} else {
0_f64
}
}
else {
} else {
0_f64
}
),
@ -224,8 +210,7 @@ fn convert_mem_data(mem_data : &[data_collection::mem::MemData]) -> Vec<(f64, f6
((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 {
} else {
data.mem_used_in_mb as f64 / data.mem_total_in_mb as f64 * 100_f64
},
);
@ -303,18 +288,14 @@ pub fn convert_network_data_points(network_data : &[data_collection::network::Ne
let num_bytes = last_num_bytes_entry.rx;
if num_bytes < 1024 {
format!("RX: {:4} B", num_bytes).to_string()
}
else if num_bytes < (1024 * 1024) {
} else if num_bytes < (1024 * 1024) {
format!("RX: {:4}KB", num_bytes / 1024).to_string()
}
else if num_bytes < (1024 * 1024 * 1024) {
} else if num_bytes < (1024 * 1024 * 1024) {
format!("RX: {:4}MB", num_bytes / 1024 / 1024).to_string()
}
else {
} else {
format!("RX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
}
}
else {
} else {
"0B".to_string()
};
@ -322,18 +303,14 @@ pub fn convert_network_data_points(network_data : &[data_collection::network::Ne
let num_bytes = last_num_bytes_entry.tx;
if num_bytes < 1024 {
format!("TX: {:4} B", num_bytes).to_string()
}
else if num_bytes < (1024 * 1024) {
} else if num_bytes < (1024 * 1024) {
format!("TX: {:4}KB", num_bytes / 1024).to_string()
}
else if num_bytes < (1024 * 1024 * 1024) {
} else if num_bytes < (1024 * 1024 * 1024) {
format!("TX: {:4}MB", num_bytes / 1024 / 1024).to_string()
}
else {
} else {
format!("TX: {:4}GB", num_bytes / 1024 / 1024 / 1024).to_string()
}
}
else {
} else {
"0B".to_string()
};

View file

@ -1,5 +1,3 @@
#![feature(async_closure)]
#[macro_use]
extern crate log;
#[macro_use]
@ -7,14 +5,17 @@ extern crate clap;
#[macro_use]
extern crate failure;
use crossterm::{input, AlternateScreen, InputEvent, KeyEvent, MouseButton, MouseEvent};
use crossterm::{
input::{input, InputEvent, KeyEvent, MouseButton, MouseEvent},
screen::AlternateScreen,
};
use std::{
io::stdout,
sync::mpsc,
thread,
time::{Duration, Instant},
};
use tui_temp_fork::{backend::CrosstermBackend, Terminal};
use tui::{backend::CrosstermBackend, Terminal};
pub mod app;
mod utils {
@ -70,8 +71,7 @@ fn main() -> error::Result<()> {
.value_of("RATE_MILLIS")
.unwrap_or(&constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS.to_string())
.parse::<u128>()?
}
else {
} else {
constants::DEFAULT_REFRESH_RATE_IN_MILLISECONDS
};
@ -79,8 +79,7 @@ fn main() -> error::Result<()> {
return Err(RustopError::InvalidArg {
message: "Please set your update rate to be greater than 250 milliseconds.".to_string(),
});
}
else if update_rate_in_milliseconds > u128::from(std::u64::MAX) {
} else if update_rate_in_milliseconds > u128::from(std::u64::MAX) {
return Err(RustopError::InvalidArg {
message: "Please set your update rate to be less than unsigned INT_MAX.".to_string(),
});
@ -88,11 +87,9 @@ fn main() -> error::Result<()> {
let temperature_type = if matches.is_present("FAHRENHEIT") {
data_collection::temperature::TemperatureType::Fahrenheit
}
else if matches.is_present("KELVIN") {
} else if matches.is_present("KELVIN") {
data_collection::temperature::TemperatureType::Kelvin
}
else {
} else {
data_collection::temperature::TemperatureType::Celsius
};
let show_average_cpu = matches.is_present("AVG_CPU");
@ -144,8 +141,7 @@ fn main() -> error::Result<()> {
_ => {}
}
}
}
else {
} else {
let mut reader = input.read_async();
loop {
if let Some(event) = reader.next() {
@ -200,8 +196,7 @@ fn main() -> error::Result<()> {
// Fix for if you set a really long time for update periods (and just gives a faster first value)
thread::sleep(Duration::from_millis(250));
first_run = false;
}
else {
} else {
thread::sleep(Duration::from_millis(update_rate_in_milliseconds as u64));
}
}

View file

@ -9,14 +9,12 @@ pub fn init_logger() -> Result<(), fern::InitError> {
message
))
})
.level(if cfg!(debug_assertions) { log::LevelFilter::Debug } else { log::LevelFilter::Info })
.chain(if cfg!(debug_assertions) {
//std::fs::OpenOptions::new().write(true).create(true).append(false).open("debug.log")?
fern::log_file("debug.log")?
}
else {
fern::log_file("logging.log")?
.level(if cfg!(debug_assertions) {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
})
.chain(fern::log_file("debug.log")?)
.apply()?;
Ok(())