diff options
author | Lukas Rysavy <lukas@rysavy.net> | 2020-12-16 03:39:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-15 21:39:17 -0500 |
commit | 120da2c85ac1d2b8cec546a91a15bfa812e7fd63 (patch) | |
tree | 6c8b336d462ad7fb04ca5356dcd08a84499f35cc /src/app | |
parent | 49cfc75aca75ccda53f1dd40be584f82094389fb (diff) |
feature: Fine grained kill signals on unix (#263)
* feature: added signal selection for killing in unix
* feature: set default signal to 15 (TERM)
* feature: selecting kill signal number with number keys
* feature: mouse selection of kill signals
* fix: restore working previous kill dialog for win
* bug: more fixes for killing on windows
* feature: made two digit number selection only work in time window
* feature: replaced grid with scrollable list for kill signal selection
* fix: handling scrolling myself
* chore: replaced tui list with span
so we actually know for sure where the buttons are
* feature: always display cancel button in kill signal selection
* chore: simplified as suggested in review
* fix: made scrolling in kill list more intuitive
* fix: differentiating macos from linux signals
* fix: fixed reversed kill confirmation movement
* chore: fixed unused warnings for windows
* feature: added G and gg keybindings for kill signal list
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/process_killer.rs | 75 | ||||
-rw-r--r-- | src/app/states.rs | 28 |
2 files changed, 59 insertions, 44 deletions
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs index e367d99c..179965fb 100644 --- a/src/app/process_killer.rs +++ b/src/app/process_killer.rs @@ -9,6 +9,7 @@ use winapi::{ }; /// This file is meant to house (OS specific) implementations on how to kill processes. +#[cfg(target_family = "unix")] use crate::utils::error::BottomError; use crate::Pid; @@ -31,46 +32,42 @@ impl Process { } } -/// Kills a process, given a PID. -pub fn kill_process_given_pid(pid: Pid) -> crate::utils::error::Result<()> { - if cfg!(target_family = "unix") { - #[cfg(any(target_family = "unix"))] - { - let output = unsafe { libc::kill(pid as i32, libc::SIGTERM) }; - if output != 0 { - // We had an error... - let err_code = std::io::Error::last_os_error().raw_os_error(); - let err = match err_code { - Some(libc::ESRCH) => "the target process did not exist.", - Some(libc::EPERM) => "the calling process does not have the permissions to terminate the target process(es).", - Some(libc::EINVAL) => "an invalid signal was specified.", - _ => "Unknown error occurred." - }; +/// Kills a process, given a PID, for unix. +#[cfg(target_family = "unix")] +pub fn kill_process_given_pid(pid: Pid, signal: usize) -> crate::utils::error::Result<()> { + let output = unsafe { libc::kill(pid as i32, signal as i32) }; + if output != 0 { + // We had an error... + let err_code = std::io::Error::last_os_error().raw_os_error(); + let err = match err_code { + Some(libc::ESRCH) => "the target process did not exist.", + Some(libc::EPERM) => "the calling process does not have the permissions to terminate the target process(es).", + Some(libc::EINVAL) => "an invalid signal was specified.", + _ => "Unknown error occurred." + }; - return if let Some(err_code) = err_code { - Err(BottomError::GenericError(format!( - "Error code {} - {}", - err_code, err, - ))) - } else { - Err(BottomError::GenericError(format!( - "Error code ??? - {}", - err, - ))) - }; - } - } - } else if cfg!(target_family = "windows") { - #[cfg(target_family = "windows")] - { - let process = Process::open(pid as DWORD)?; - process.kill()?; - } - } else { - return Err(BottomError::GenericError( - "Sorry, support operating systems outside the main three are not implemented yet!" - .to_string(), - )); + return if let Some(err_code) = err_code { + Err(BottomError::GenericError(format!( + "Error code {} - {}", + err_code, err, + ))) + } else { + Err(BottomError::GenericError(format!( + "Error code ??? - {}", + err, + ))) + }; + } + + Ok(()) +} + +/// Kills a process, given a PID, for windows. +#[cfg(target_os = "windows")] +pub fn kill_process_given_pid(pid: Pid) -> crate::utils::error::Result<()> { + { + let process = Process::open(pid as DWORD)?; + process.kill()?; } Ok(()) diff --git a/src/app/states.rs b/src/app/states.rs index fadb7bcf..fe32a50d 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -40,14 +40,32 @@ pub struct AppScrollWidgetState { pub table_state: TableState, } +#[derive(PartialEq)] +pub enum KillSignal { + CANCEL, + KILL(usize), +} + +impl Default for KillSignal { + #[cfg(target_family = "unix")] + fn default() -> Self { + KillSignal::KILL(15) + } + #[cfg(target_os = "windows")] + fn default() -> Self { + KillSignal::KILL(1) + } +} + #[derive(Default)] pub struct AppDeleteDialogState { pub is_showing_dd: bool, - pub is_on_yes: bool, // Defaults to "No" - pub yes_tlc: Option<(u16, u16)>, - pub yes_brc: Option<(u16, u16)>, - pub no_tlc: Option<(u16, u16)>, - pub no_brc: Option<(u16, u16)>, + pub selected_signal: KillSignal, + // tl x, tl y, br x, br y + pub button_positions: Vec<(u16, u16, u16, u16, usize)>, + pub keyboard_signal_select: usize, + pub last_number_press: Option<Instant>, + pub scroll_pos: usize, } pub struct AppHelpDialogState { |