Note this is not 100% complete - there's some nasty code used to just get functionality down. Simple search option added, flag added, no way of switching in-program yet however.
This commit is contained in:
parent
1b65fa022a
commit
5d0c8a9f32
|
@ -63,9 +63,10 @@ pub struct App {
|
|||
last_key_press: Instant,
|
||||
pub canvas_data: canvas::CanvasData,
|
||||
enable_grouping: bool,
|
||||
enable_searching: bool,
|
||||
enable_searching: bool, // TODO: [OPT] group together?
|
||||
current_search_query: String,
|
||||
searching_pid: bool,
|
||||
pub use_simple: bool,
|
||||
current_regex: std::result::Result<regex::Regex, regex::Error>,
|
||||
}
|
||||
|
||||
|
@ -109,7 +110,8 @@ impl App {
|
|||
enable_searching: false,
|
||||
current_search_query: String::default(),
|
||||
searching_pid: false,
|
||||
current_regex: BASE_REGEX.clone(), //TODO: [OPT] seems like a thing we can switch to lt for if not fast
|
||||
use_simple: false,
|
||||
current_regex: BASE_REGEX.clone(), //TODO: [OPT] seems like a thing we can switch to lifetimes to avoid cloning
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -319,7 +319,6 @@ pub fn draw_data<B: backend::Backend>(
|
|||
)
|
||||
.split(vertical_chunks[0]);
|
||||
|
||||
debug!("Height: {}", bottom_chunks[0].height);
|
||||
let network_chunk = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(0)
|
||||
|
|
|
@ -140,7 +140,49 @@ pub fn update_disk_row(app_data: &data_collection::Data) -> Vec<Vec<String>> {
|
|||
disk_vector
|
||||
}
|
||||
|
||||
pub fn update_process_row(
|
||||
pub fn simple_update_process_row(
|
||||
app_data: &data_collection::Data, matching_string: &str, use_pid: bool,
|
||||
) -> (Vec<ConvertedProcessData>, Vec<ConvertedProcessData>) {
|
||||
let process_vector: Vec<ConvertedProcessData> = app_data
|
||||
.list_of_processes
|
||||
.iter()
|
||||
.filter(|process| {
|
||||
if use_pid {
|
||||
process
|
||||
.pid
|
||||
.to_string()
|
||||
.to_ascii_lowercase()
|
||||
.contains(matching_string)
|
||||
} else {
|
||||
process.name.to_ascii_lowercase().contains(matching_string)
|
||||
}
|
||||
})
|
||||
.map(|process| return_mapped_process(process, app_data))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut grouped_process_vector: Vec<ConvertedProcessData> = Vec::new();
|
||||
if let Some(grouped_list_of_processes) = &app_data.grouped_list_of_processes {
|
||||
grouped_process_vector = grouped_list_of_processes
|
||||
.iter()
|
||||
.filter(|process| {
|
||||
if use_pid {
|
||||
process
|
||||
.pid
|
||||
.to_string()
|
||||
.to_ascii_lowercase()
|
||||
.contains(matching_string)
|
||||
} else {
|
||||
process.name.to_ascii_lowercase().contains(matching_string)
|
||||
}
|
||||
})
|
||||
.map(|process| return_mapped_process(process, app_data))
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
|
||||
(process_vector, grouped_process_vector)
|
||||
}
|
||||
|
||||
pub fn regex_update_process_row(
|
||||
app_data: &data_collection::Data, regex_matcher: &std::result::Result<Regex, regex::Error>,
|
||||
use_pid: bool,
|
||||
) -> (Vec<ConvertedProcessData>, Vec<ConvertedProcessData>) {
|
||||
|
@ -158,26 +200,7 @@ pub fn update_process_row(
|
|||
true
|
||||
}
|
||||
})
|
||||
.map(|process| ConvertedProcessData {
|
||||
pid: process.pid,
|
||||
name: process.name.to_string(),
|
||||
cpu_usage: format!("{:.1}%", process.cpu_usage_percent),
|
||||
mem_usage: format!(
|
||||
"{:.1}%",
|
||||
if let Some(mem_usage) = process.mem_usage_percent {
|
||||
mem_usage
|
||||
} else if let Some(mem_usage_kb) = process.mem_usage_kb {
|
||||
if let Some(mem_data) = app_data.memory.last() {
|
||||
(mem_usage_kb / 1000) as f64 / mem_data.mem_total_in_mb as f64 * 100_f64
|
||||
} else {
|
||||
0_f64
|
||||
}
|
||||
} else {
|
||||
0_f64
|
||||
}
|
||||
),
|
||||
group: vec![],
|
||||
})
|
||||
.map(|process| return_mapped_process(process, app_data))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut grouped_process_vector: Vec<ConvertedProcessData> = Vec::new();
|
||||
|
@ -195,36 +218,38 @@ pub fn update_process_row(
|
|||
true
|
||||
}
|
||||
})
|
||||
.map(|process| ConvertedProcessData {
|
||||
pid: process.pid,
|
||||
name: process.name.to_string(),
|
||||
cpu_usage: format!("{:.1}%", process.cpu_usage_percent),
|
||||
mem_usage: format!(
|
||||
"{:.1}%",
|
||||
if let Some(mem_usage) = process.mem_usage_percent {
|
||||
mem_usage
|
||||
} else if let Some(mem_usage_kb) = process.mem_usage_kb {
|
||||
if let Some(mem_data) = app_data.memory.last() {
|
||||
(mem_usage_kb / 1000) as f64 / mem_data.mem_total_in_mb as f64 * 100_f64
|
||||
} else {
|
||||
0_f64
|
||||
}
|
||||
} else {
|
||||
0_f64
|
||||
}
|
||||
),
|
||||
group: if let Some(pid_vec) = &process.pid_vec {
|
||||
pid_vec.to_vec()
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
})
|
||||
.map(|process| return_mapped_process(process, app_data))
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
|
||||
(process_vector, grouped_process_vector)
|
||||
}
|
||||
|
||||
fn return_mapped_process(
|
||||
process: &data_collection::processes::ProcessData, app_data: &data_collection::Data,
|
||||
) -> ConvertedProcessData {
|
||||
ConvertedProcessData {
|
||||
pid: process.pid,
|
||||
name: process.name.to_string(),
|
||||
cpu_usage: format!("{:.1}%", process.cpu_usage_percent),
|
||||
mem_usage: format!(
|
||||
"{:.1}%",
|
||||
if let Some(mem_usage) = process.mem_usage_percent {
|
||||
mem_usage
|
||||
} else if let Some(mem_usage_kb) = process.mem_usage_kb {
|
||||
if let Some(mem_data) = app_data.memory.last() {
|
||||
(mem_usage_kb / 1000) as f64 / mem_data.mem_total_in_mb as f64 * 100_f64 // TODO: [OPT] Get rid of this
|
||||
} else {
|
||||
0_f64
|
||||
}
|
||||
} else {
|
||||
0_f64
|
||||
}
|
||||
),
|
||||
group: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_cpu_data_points(
|
||||
show_avg_cpu: bool, app_data: &data_collection::Data,
|
||||
) -> Vec<ConvertedCpuData> {
|
||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -73,6 +73,7 @@ fn main() -> error::Result<()> {
|
|||
//(@arg CONFIG_LOCATION: -co --config +takes_value "Sets the location of the config file. Expects a config file in the JSON format.")
|
||||
(@arg BASIC_MODE: -b --basic "Sets bottom to basic mode, not showing graphs and only showing basic tables.")
|
||||
(@arg GROUP_PROCESSES: -g --group "Groups processes with the same name together on launch.")
|
||||
(@arg SEARCH_DEFAULT_USE_SIMPLE: -s --simple_search "Uses a simple case-insensitive string comparison to search processes by default.")
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
|
@ -129,6 +130,11 @@ fn main() -> error::Result<()> {
|
|||
app.toggle_grouping();
|
||||
}
|
||||
|
||||
// Set default search method
|
||||
if matches.is_present("SEARCH_DEFAULT_USE_SIMPLE") {
|
||||
app.use_simple = true;
|
||||
}
|
||||
|
||||
// Set up up tui and crossterm
|
||||
let mut stdout = stdout();
|
||||
enable_raw_mode()?;
|
||||
|
@ -286,8 +292,6 @@ fn main() -> error::Result<()> {
|
|||
app.canvas_data.swap_data = update_swap_data_points(&app.data);
|
||||
app.canvas_data.cpu_data =
|
||||
update_cpu_data_points(app.show_average_cpu, &app.data);
|
||||
|
||||
//debug!("Update event complete.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -384,11 +388,19 @@ fn handle_process_sorting(app: &mut app::App) {
|
|||
app.process_sorting_reverse,
|
||||
);
|
||||
|
||||
let tuple_results = update_process_row(
|
||||
&app.data,
|
||||
app.get_current_regex_matcher(),
|
||||
app.is_searching_with_pid(),
|
||||
);
|
||||
let tuple_results = if app.use_simple {
|
||||
simple_update_process_row(
|
||||
&app.data,
|
||||
&(app.get_current_search_query().to_ascii_lowercase()),
|
||||
app.is_searching_with_pid(),
|
||||
)
|
||||
} else {
|
||||
regex_update_process_row(
|
||||
&app.data,
|
||||
app.get_current_regex_matcher(),
|
||||
app.is_searching_with_pid(),
|
||||
)
|
||||
};
|
||||
app.canvas_data.process_data = tuple_results.0;
|
||||
app.canvas_data.grouped_process_data = tuple_results.1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue