More fixes for Windows.

This commit is contained in:
Clement Tsang 2019-09-25 00:48:53 -04:00 committed by ClementTsang
parent 9df0b2e4e2
commit a24e5dbbcf
3 changed files with 22 additions and 32 deletions

View File

@ -36,11 +36,12 @@ pub struct App {
pub data : data_collection::Data,
pub scroll_direction : ScrollDirection,
pub previous_process_position : i64,
awaiting_d : bool,
awaiting_second_d : bool,
pub use_dot : bool,
}
impl App {
pub fn new(show_average_cpu : bool, temperature_type : temperature::TemperatureType, update_rate_in_milliseconds : u64) -> 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,
should_quit : false,
@ -57,7 +58,8 @@ impl App {
data : data_collection::Data::default(),
scroll_direction : ScrollDirection::DOWN,
previous_process_position : 0,
awaiting_d : false,
awaiting_second_d : false,
use_dot,
}
}
@ -65,12 +67,12 @@ impl App {
match c {
'q' => self.should_quit = true,
'd' => {
if self.awaiting_d {
self.awaiting_d = false;
if self.awaiting_second_d {
self.awaiting_second_d = false;
self.kill_highlighted_process().unwrap_or(()); // TODO: Should this be handled?
}
else {
self.awaiting_d = true;
self.awaiting_second_d = true;
}
}
'c' => {
@ -121,8 +123,8 @@ impl App {
_ => {}
}
if self.awaiting_d && c != 'd' {
self.awaiting_d = false;
if self.awaiting_second_d && c != 'd' {
self.awaiting_second_d = false;
}
}

View File

@ -13,7 +13,6 @@ const TEXT_COLOUR : Color = Color::Gray;
const GRAPH_COLOUR : Color = Color::Gray;
const BORDER_STYLE_COLOUR : Color = Color::Gray;
const HIGHLIGHTED_BORDER_STYLE_COLOUR : Color = Color::LightBlue;
const GRAPH_MARKER : Marker = Marker::Braille;
#[derive(Default)]
pub struct CanvasData {
@ -88,7 +87,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
dataset_vector.push(
Dataset::default()
.name(&cpu.0)
.marker(GRAPH_MARKER)
.marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(COLOUR_LIST[i - avg_cpu_exist_offset % COLOUR_LIST.len()]))
.data(&(cpu.1)),
);
@ -98,7 +97,7 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
dataset_vector.push(
Dataset::default()
.name(&canvas_data.cpu_data[0].0)
.marker(GRAPH_MARKER)
.marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(COLOUR_LIST[canvas_data.cpu_data.len() - 1 % COLOUR_LIST.len()]))
.data(&(canvas_data.cpu_data[0].1)),
);
@ -139,12 +138,12 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.datasets(&[
Dataset::default()
.name(&("RAM:".to_string() + &format!("{:3}%", (canvas_data.mem_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))))
.marker(GRAPH_MARKER)
.marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(Color::LightBlue))
.data(&canvas_data.mem_data),
Dataset::default()
.name(&("SWP:".to_string() + &format!("{:3}%", (canvas_data.swap_data.last().unwrap_or(&(0_f64, 0_f64)).1.round() as u64))))
.marker(GRAPH_MARKER)
.marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(Color::LightYellow))
.data(&canvas_data.swap_data),
])
@ -215,12 +214,12 @@ pub fn draw_data<B : backend::Backend>(terminal : &mut Terminal<B>, app_state :
.datasets(&[
Dataset::default()
.name(&(canvas_data.rx_display))
.marker(GRAPH_MARKER)
.marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(Color::LightBlue))
.data(&canvas_data.network_data_rx),
Dataset::default()
.name(&(canvas_data.tx_display))
.marker(GRAPH_MARKER)
.marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille })
.style(Style::default().fg(Color::LightYellow))
.data(&canvas_data.network_data_tx),
])

View File

@ -7,13 +7,8 @@ extern crate clap;
#[macro_use]
extern crate failure;
use crossterm::{input, queue, AlternateScreen, InputEvent, KeyEvent, MouseButton, MouseEvent};
use std::{
io::{stdout, Write},
sync::mpsc,
thread,
time::Duration,
};
use crossterm::{input, AlternateScreen, InputEvent, KeyEvent, MouseButton, MouseEvent};
use std::{io::stdout, sync::mpsc, thread, time::Duration};
use tui_temp_fork::{backend::CrosstermBackend, Terminal};
pub mod app;
@ -49,6 +44,7 @@ fn main() -> error::Result<()> {
(about: crate_description!())
//(@arg THEME: -t --theme +takes_value "Sets a colour theme.")
(@arg AVG_CPU: -a --avgcpu "Enables showing the average CPU usage.")
(@arg DOT_MARKER: -m --dot_marker "Use a dot marker instead of the default braille marker. May be needed in things like Powershell.")
//(@arg DEBUG: -d --debug "Enables debug mode.") // TODO: This isn't done yet!
(@group TEMPERATURE_TYPE =>
(@arg CELSIUS : -c --celsius "Sets the temperature type to Celsius. This is the default option.")
@ -83,20 +79,14 @@ fn main() -> error::Result<()> {
data_collection::temperature::TemperatureType::Celsius
};
let show_average_cpu = matches.is_present("AVG_CPU");
let use_dot = matches.is_present("DOT_MARKER");
// Create "app" struct, which will control most of the program and store settings/state
let mut app = app::App::new(show_average_cpu, temperature_type, update_rate_in_milliseconds as u64);
let mut app = app::App::new(show_average_cpu, temperature_type, update_rate_in_milliseconds as u64, use_dot);
// Set up up tui and crossterm
let screen = AlternateScreen::to_alternate(true)?;
let mut stdout = stdout();
if cfg!(target_os = "windows") {
screen.to_main()?;
crossterm::RawScreen::into_raw_mode()?;
queue!(stdout, crossterm::Clear(crossterm::ClearType::All), crossterm::BlinkOff)?;
stdout.flush()?;
}
let stdout = stdout();
let backend = CrosstermBackend::with_alternate_screen(stdout, screen)?;
let mut terminal = Terminal::new(backend)?;
@ -129,7 +119,6 @@ fn main() -> error::Result<()> {
_ => {}
}
}
thread::sleep(Duration::from_millis(50));
}
});
}