mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-29 16:44:54 +02:00
Fix dd with new changes
This commit is contained in:
parent
0ab4b7f7cc
commit
3327087443
43
src/app.rs
43
src/app.rs
@ -5,7 +5,7 @@ use std::time::Instant;
|
|||||||
pub mod data_farmer;
|
pub mod data_farmer;
|
||||||
use data_farmer::*;
|
use data_farmer::*;
|
||||||
|
|
||||||
use crate::{canvas, constants, data_conversion::ConvertedProcessData, utils::error::Result};
|
use crate::{canvas, constants, utils::error::Result};
|
||||||
|
|
||||||
mod process_killer;
|
mod process_killer;
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ pub struct App {
|
|||||||
pub show_help: bool,
|
pub show_help: bool,
|
||||||
pub show_dd: bool,
|
pub show_dd: bool,
|
||||||
pub dd_err: Option<String>,
|
pub dd_err: Option<String>,
|
||||||
to_delete_process_list: Option<Vec<ConvertedProcessData>>,
|
to_delete_process_list: Option<(String, Vec<u32>)>,
|
||||||
pub is_frozen: bool,
|
pub is_frozen: bool,
|
||||||
pub left_legend: bool,
|
pub left_legend: bool,
|
||||||
pub use_current_cpu_total: bool,
|
pub use_current_cpu_total: bool,
|
||||||
@ -390,12 +390,37 @@ impl App {
|
|||||||
if self.awaiting_second_char && self.second_char == 'd' {
|
if self.awaiting_second_char && self.second_char == 'd' {
|
||||||
self.awaiting_second_char = false;
|
self.awaiting_second_char = false;
|
||||||
self.second_char = ' ';
|
self.second_char = ' ';
|
||||||
let current_process = Vec::new();
|
|
||||||
|
|
||||||
// TODO: Fix
|
if self.currently_selected_process_position
|
||||||
|
< self.canvas_data.finalized_process_data.len() as i64
|
||||||
|
{
|
||||||
|
let current_process = if self.is_grouped() {
|
||||||
|
let group_pids = &self.canvas_data.finalized_process_data
|
||||||
|
[self.currently_selected_process_position as usize]
|
||||||
|
.group_pids;
|
||||||
|
|
||||||
|
let mut ret = ("".to_string(), group_pids.clone());
|
||||||
|
|
||||||
|
for pid in group_pids {
|
||||||
|
if let Some(process) =
|
||||||
|
self.canvas_data.process_data.get(&pid)
|
||||||
|
{
|
||||||
|
ret.0 = process.name.clone();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret
|
||||||
|
} else {
|
||||||
|
let process = self.canvas_data.finalized_process_data
|
||||||
|
[self.currently_selected_process_position as usize]
|
||||||
|
.clone();
|
||||||
|
(process.name.clone(), vec![process.pid])
|
||||||
|
};
|
||||||
|
|
||||||
|
self.to_delete_process_list = Some(current_process);
|
||||||
|
self.show_dd = true;
|
||||||
|
}
|
||||||
|
|
||||||
self.to_delete_process_list = Some(current_process);
|
|
||||||
self.show_dd = true;
|
|
||||||
self.reset_multi_tap_keys();
|
self.reset_multi_tap_keys();
|
||||||
} else {
|
} else {
|
||||||
self.awaiting_second_char = true;
|
self.awaiting_second_char = true;
|
||||||
@ -490,8 +515,8 @@ impl App {
|
|||||||
// Technically unnecessary but this is a good check...
|
// Technically unnecessary but this is a good check...
|
||||||
if let WidgetPosition::Process = self.current_widget_selected {
|
if let WidgetPosition::Process = self.current_widget_selected {
|
||||||
if let Some(current_selected_processes) = &(self.to_delete_process_list) {
|
if let Some(current_selected_processes) = &(self.to_delete_process_list) {
|
||||||
for current_selected_process in current_selected_processes {
|
for pid in ¤t_selected_processes.1 {
|
||||||
process_killer::kill_process_given_pid(current_selected_process.pid)?;
|
process_killer::kill_process_given_pid(*pid)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.to_delete_process_list = None;
|
self.to_delete_process_list = None;
|
||||||
@ -499,7 +524,7 @@ impl App {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current_highlighted_process_list(&self) -> Option<Vec<ConvertedProcessData>> {
|
pub fn get_to_delete_processes(&self) -> Option<(String, Vec<u32>)> {
|
||||||
self.to_delete_process_list.clone()
|
self.to_delete_process_list.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,23 +239,23 @@ pub fn draw_data<B: backend::Backend>(
|
|||||||
.alignment(Alignment::Center)
|
.alignment(Alignment::Center)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.render(&mut f, middle_dialog_chunk[1]);
|
.render(&mut f, middle_dialog_chunk[1]);
|
||||||
} else if let Some(process_list) = app_state.get_current_highlighted_process_list() {
|
} else if let Some(to_kill_processes) = app_state.get_to_delete_processes() {
|
||||||
if let Some(process) = process_list.first() {
|
if let Some(first_pid) = to_kill_processes.1.first() {
|
||||||
let dd_text = [
|
let dd_text = [
|
||||||
if app_state.is_grouped() {
|
if app_state.is_grouped() {
|
||||||
Text::raw(format!(
|
Text::raw(format!(
|
||||||
"\nAre you sure you want to kill {} process(es) with name {}?",
|
"\nAre you sure you want to kill {} process(es) with name {}?",
|
||||||
process_list.len(), process.name
|
to_kill_processes.1.len(), to_kill_processes.0
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Text::raw(format!(
|
Text::raw(format!(
|
||||||
"\nAre you sure you want to kill process {} with PID {}?",
|
"\nAre you sure you want to kill process {} with PID {}?",
|
||||||
process.name, process.pid
|
to_kill_processes.0, first_pid
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
Text::raw("\n\nPress ENTER to proceed, ESC to exit."),
|
Text::raw("\n\nPress ENTER to proceed, ESC to exit."),
|
||||||
Text::raw("\nNote that if bottom is frozen, it must be unfrozen for changes to be shown."),
|
Text::raw("\nNote that if bottom is frozen, it must be unfrozen for changes to be shown."),
|
||||||
];
|
];
|
||||||
|
|
||||||
Paragraph::new(dd_text.iter())
|
Paragraph::new(dd_text.iter())
|
||||||
.block(
|
.block(
|
||||||
@ -268,6 +268,7 @@ pub fn draw_data<B: backend::Backend>(
|
|||||||
.wrap(true)
|
.wrap(true)
|
||||||
.render(&mut f, middle_dialog_chunk[1]);
|
.render(&mut f, middle_dialog_chunk[1]);
|
||||||
} else {
|
} else {
|
||||||
|
// This is a bit nasty, but it works well... I guess.
|
||||||
app_state.show_dd = false;
|
app_state.show_dd = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user