diff --git a/README.md b/README.md index 4f2b9e4b..b3e19f06 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,9 @@ Currently, I'm unable to really dev or test on MacOS, so I'm not sure how well t - `-h`, `--help` to show the help screen and exit (basically has all of the below CLI option info). -- `-a`, `--avgcpu` enables showing the average CPU usage on rustop +- `-a`, `--avgcpu` enables showing the average CPU usage on rustop. + +- `-m`, `--dot-marker` uses a dot marker instead of the default braille marker. This is useful for things like Powershell which display braille markers incorrectly. - `-c`, `--celsius` displays the temperature type in Celsius. This is the default. diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs index 3e5feb76..bab07241 100644 --- a/src/app/process_killer.rs +++ b/src/app/process_killer.rs @@ -1,6 +1,9 @@ /// This file is meant to house (OS specific) implementations on how to kill processes. use std::process::Command; + +#[cfg(target_os = "windows")] use std::ptr::null_mut; +#[cfg(target_os = "windows")] use winapi::{ shared::{minwindef::DWORD, ntdef::HANDLE}, um::{ @@ -10,7 +13,10 @@ use winapi::{ }; // Copied from SO: https://stackoverflow.com/a/55231715 +#[cfg(target_os = "windows")] struct Process(HANDLE); + +#[cfg(target_os = "windows")] impl Process { fn open(pid : DWORD) -> Result { let pc = unsafe { OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_TERMINATE, 0, pid) }; @@ -25,11 +31,6 @@ impl Process { Ok(()) } } -impl Drop for Process { - fn drop(&mut self) { - unsafe { winapi::um::handleapi::CloseHandle(self.0) }; - } -} /// Kills a process, given a PID. pub fn kill_process_given_pid(pid : u64) -> crate::utils::error::Result<()> { @@ -38,7 +39,9 @@ pub fn kill_process_given_pid(pid : u64) -> crate::utils::error::Result<()> { Command::new("kill").arg(pid.to_string()).output()?; } 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") { diff --git a/src/canvas.rs b/src/canvas.rs index 9d0bee14..b6e185c0 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -87,7 +87,7 @@ pub fn draw_data(terminal : &mut Terminal, app_state : dataset_vector.push( Dataset::default() .name(&cpu.0) - .marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille }) + .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)), ); @@ -97,7 +97,7 @@ pub fn draw_data(terminal : &mut Terminal, app_state : dataset_vector.push( Dataset::default() .name(&canvas_data.cpu_data[0].0) - .marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille }) + .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)), ); @@ -138,12 +138,12 @@ pub fn draw_data(terminal : &mut Terminal, 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(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille }) + .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(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille }) + .marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille }) .style(Style::default().fg(Color::LightYellow)) .data(&canvas_data.swap_data), ]) @@ -214,12 +214,12 @@ pub fn draw_data(terminal : &mut Terminal, app_state : .datasets(&[ Dataset::default() .name(&(canvas_data.rx_display)) - .marker(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille }) + .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(if (&app_state).use_dot { Marker::Dot } else { Marker::Braille }) + .marker(if app_state.use_dot { Marker::Dot } else { Marker::Braille }) .style(Style::default().fg(Color::LightYellow)) .data(&canvas_data.network_data_tx), ]) diff --git a/src/main.rs b/src/main.rs index 4c6eebe7..cabe2fd1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,7 +90,6 @@ fn main() -> error::Result<()> { let backend = CrosstermBackend::with_alternate_screen(stdout, screen)?; let mut terminal = Terminal::new(backend)?; - terminal.set_cursor(0, 0)?; terminal.hide_cursor()?; terminal.clear()?; @@ -100,11 +99,11 @@ fn main() -> error::Result<()> { let tx = tx.clone(); thread::spawn(move || { let input = input(); - input.enable_mouse_mode().unwrap(); // TODO: I think this is broken on windows... + input.enable_mouse_mode().unwrap(); - let mut reader = input.read_async(); - loop { - if let Some(event) = reader.next() { + if cfg!(target_os = "linux") { + let reader = input.read_sync(); + for event in reader { match event { InputEvent::Keyboard(key) => { if tx.send(Event::KeyInput(key.clone())).is_err() { @@ -120,6 +119,26 @@ fn main() -> error::Result<()> { } } } + else { + let mut reader = input.read_async(); + loop { + if let Some(event) = reader.next() { + match event { + InputEvent::Keyboard(key) => { + if tx.send(Event::KeyInput(key.clone())).is_err() { + return; + } + } + InputEvent::Mouse(mouse) => { + if tx.send(Event::MouseInput(mouse)).is_err() { + return; + } + } + _ => {} + } + } + } + } }); }