mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-22 21:24:49 +02:00
Add g and GG logic
This commit is contained in:
parent
baf588be8a
commit
bf02afcf79
78
src/app.rs
78
src/app.rs
@ -40,7 +40,8 @@ pub struct App {
|
|||||||
pub previous_disk_position: i64,
|
pub previous_disk_position: i64,
|
||||||
pub previous_temp_position: i64,
|
pub previous_temp_position: i64,
|
||||||
pub previous_process_position: i64,
|
pub previous_process_position: i64,
|
||||||
awaiting_second_d: bool,
|
awaiting_second_char: bool,
|
||||||
|
second_char: char,
|
||||||
pub use_dot: bool,
|
pub use_dot: bool,
|
||||||
pub show_help: bool,
|
pub show_help: bool,
|
||||||
pub is_frozen: bool,
|
pub is_frozen: bool,
|
||||||
@ -66,7 +67,8 @@ impl App {
|
|||||||
previous_process_position: 0,
|
previous_process_position: 0,
|
||||||
previous_disk_position: 0,
|
previous_disk_position: 0,
|
||||||
previous_temp_position: 0,
|
previous_temp_position: 0,
|
||||||
awaiting_second_d: false,
|
awaiting_second_char: false,
|
||||||
|
second_char: ' ',
|
||||||
use_dot,
|
use_dot,
|
||||||
show_help: false,
|
show_help: false,
|
||||||
is_frozen: false,
|
is_frozen: false,
|
||||||
@ -79,7 +81,8 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn reset_multi_tap_keys(&mut self) {
|
fn reset_multi_tap_keys(&mut self) {
|
||||||
self.awaiting_second_d = false;
|
self.awaiting_second_char = false;
|
||||||
|
self.second_char = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_enter(&mut self) {}
|
pub fn on_enter(&mut self) {}
|
||||||
@ -88,11 +91,11 @@ impl App {
|
|||||||
if self.show_help {
|
if self.show_help {
|
||||||
self.show_help = false;
|
self.show_help = false;
|
||||||
}
|
}
|
||||||
self.awaiting_second_d = false;
|
self.reset_multi_tap_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: How should we make it for process panel specific hotkeys? Only if we're on process panel? Or what?
|
// 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, caught_char: char) {
|
||||||
if !self.show_help {
|
if !self.show_help {
|
||||||
let current_key_press_inst = Instant::now();
|
let current_key_press_inst = Instant::now();
|
||||||
if current_key_press_inst.duration_since(self.last_key_press).as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS {
|
if current_key_press_inst.duration_since(self.last_key_press).as_millis() > constants::MAX_KEY_TIMEOUT_IN_MILLISECONDS {
|
||||||
@ -100,13 +103,26 @@ impl App {
|
|||||||
}
|
}
|
||||||
self.last_key_press = current_key_press_inst;
|
self.last_key_press = current_key_press_inst;
|
||||||
|
|
||||||
match c {
|
match caught_char {
|
||||||
'd' => {
|
'd' => {
|
||||||
if self.awaiting_second_d {
|
if self.awaiting_second_char && self.second_char == 'd' {
|
||||||
self.awaiting_second_d = false;
|
self.awaiting_second_char = false;
|
||||||
self.kill_highlighted_process().unwrap_or(());
|
self.second_char = ' ';
|
||||||
|
// TODO: Redo this in DD rewrite!
|
||||||
|
//self.kill_highlighted_process().unwrap_or(());
|
||||||
} else {
|
} else {
|
||||||
self.awaiting_second_d = true;
|
self.awaiting_second_char = true;
|
||||||
|
self.second_char = 'd';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'g' => {
|
||||||
|
if self.awaiting_second_char && self.second_char == 'g' {
|
||||||
|
self.awaiting_second_char = false;
|
||||||
|
self.second_char = ' ';
|
||||||
|
self.skip_to_first();
|
||||||
|
} else {
|
||||||
|
self.awaiting_second_char = true;
|
||||||
|
self.second_char = 'g';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'f' => {
|
'f' => {
|
||||||
@ -162,15 +178,15 @@ impl App {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.awaiting_second_d && c != 'd' {
|
if self.awaiting_second_char && caught_char != self.second_char {
|
||||||
self.awaiting_second_d = false;
|
self.awaiting_second_char = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kill_highlighted_process(&self) -> crate::utils::error::Result<()> {
|
fn _kill_highlighted_process(&self) -> crate::utils::error::Result<()> {
|
||||||
let current_pid = u64::from(self.data.list_of_processes[self.currently_selected_process_position as usize].pid);
|
let current_pid = u64::from(self.data.list_of_processes[self.currently_selected_process_position as usize].pid);
|
||||||
process_killer::kill_process_given_pid(current_pid)?;
|
process_killer::_kill_process_given_pid(current_pid)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +206,7 @@ impl App {
|
|||||||
ApplicationPosition::TEMP => ApplicationPosition::MEM,
|
ApplicationPosition::TEMP => ApplicationPosition::MEM,
|
||||||
_ => self.current_application_position,
|
_ => self.current_application_position,
|
||||||
};
|
};
|
||||||
self.awaiting_second_d = false;
|
self.reset_multi_tap_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_right(&mut self) {
|
pub fn on_right(&mut self) {
|
||||||
@ -199,7 +215,7 @@ impl App {
|
|||||||
ApplicationPosition::NETWORK => ApplicationPosition::PROCESS,
|
ApplicationPosition::NETWORK => ApplicationPosition::PROCESS,
|
||||||
_ => self.current_application_position,
|
_ => self.current_application_position,
|
||||||
};
|
};
|
||||||
self.awaiting_second_d = false;
|
self.reset_multi_tap_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_up(&mut self) {
|
pub fn on_up(&mut self) {
|
||||||
@ -211,7 +227,7 @@ impl App {
|
|||||||
ApplicationPosition::DISK => ApplicationPosition::TEMP,
|
ApplicationPosition::DISK => ApplicationPosition::TEMP,
|
||||||
_ => self.current_application_position,
|
_ => self.current_application_position,
|
||||||
};
|
};
|
||||||
self.awaiting_second_d = false;
|
self.reset_multi_tap_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_down(&mut self) {
|
pub fn on_down(&mut self) {
|
||||||
@ -222,7 +238,29 @@ impl App {
|
|||||||
ApplicationPosition::DISK => ApplicationPosition::PROCESS,
|
ApplicationPosition::DISK => ApplicationPosition::PROCESS,
|
||||||
_ => self.current_application_position,
|
_ => self.current_application_position,
|
||||||
};
|
};
|
||||||
self.awaiting_second_d = false;
|
self.reset_multi_tap_keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn skip_to_first(&mut self) {
|
||||||
|
match self.current_application_position {
|
||||||
|
ApplicationPosition::PROCESS => self.currently_selected_process_position = 0,
|
||||||
|
ApplicationPosition::TEMP => self.currently_selected_temperature_position = 0,
|
||||||
|
ApplicationPosition::DISK => self.currently_selected_disk_position = 0,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
self.scroll_direction = ScrollDirection::DOWN;
|
||||||
|
self.reset_multi_tap_keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn skip_to_last(&mut self) {
|
||||||
|
match self.current_application_position {
|
||||||
|
ApplicationPosition::PROCESS => self.currently_selected_process_position = self.data.list_of_processes.len() as i64 - 1,
|
||||||
|
ApplicationPosition::TEMP => self.currently_selected_temperature_position = self.data.list_of_temperature_sensor.len() as i64 - 1,
|
||||||
|
ApplicationPosition::DISK => self.currently_selected_disk_position = self.data.list_of_disks.len() as i64 - 1,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
self.scroll_direction = ScrollDirection::DOWN;
|
||||||
|
self.reset_multi_tap_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decrement_position_count(&mut self) {
|
pub fn decrement_position_count(&mut self) {
|
||||||
@ -233,7 +271,7 @@ impl App {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
self.scroll_direction = ScrollDirection::UP;
|
self.scroll_direction = ScrollDirection::UP;
|
||||||
self.awaiting_second_d = false;
|
self.reset_multi_tap_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn increment_position_count(&mut self) {
|
pub fn increment_position_count(&mut self) {
|
||||||
@ -244,7 +282,7 @@ impl App {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
self.scroll_direction = ScrollDirection::DOWN;
|
self.scroll_direction = ScrollDirection::DOWN;
|
||||||
self.awaiting_second_d = false;
|
self.reset_multi_tap_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_process_position(&mut self, num_to_change_by: i64) {
|
fn change_process_position(&mut self, num_to_change_by: i64) {
|
||||||
|
@ -33,7 +33,7 @@ impl Process {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Kills a process, given a PID.
|
/// Kills a process, given a PID.
|
||||||
pub fn kill_process_given_pid(pid: u64) -> crate::utils::error::Result<()> {
|
pub fn _kill_process_given_pid(pid: u64) -> crate::utils::error::Result<()> {
|
||||||
if cfg!(target_os = "linux") {
|
if cfg!(target_os = "linux") {
|
||||||
// Linux
|
// Linux
|
||||||
Command::new("kill").arg(pid.to_string()).output()?;
|
Command::new("kill").arg(pid.to_string()).output()?;
|
||||||
|
@ -190,6 +190,7 @@ fn main() -> error::Result<()> {
|
|||||||
// If only a code, and no modifiers, don't bother...
|
// If only a code, and no modifiers, don't bother...
|
||||||
match event.code {
|
match event.code {
|
||||||
KeyCode::Char('q') => break,
|
KeyCode::Char('q') => break,
|
||||||
|
KeyCode::Char('G') => app.skip_to_last(),
|
||||||
KeyCode::Char('h') => app.on_left(),
|
KeyCode::Char('h') => app.on_left(),
|
||||||
KeyCode::Char('l') => app.on_right(),
|
KeyCode::Char('l') => app.on_right(),
|
||||||
KeyCode::Char('k') => app.on_up(),
|
KeyCode::Char('k') => app.on_up(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user