summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs98
1 files changed, 45 insertions, 53 deletions
diff --git a/src/lib.rs b/src/lib.rs
index ec42b775..85f0d7e9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -237,10 +237,10 @@ pub fn create_or_get_config(config_path: &Option<PathBuf>) -> error::Result<Conf
pub fn try_drawing(
terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>,
- app: &mut App, painter: &mut canvas::Painter, is_debug: bool,
+ app: &mut App, painter: &mut canvas::Painter,
) -> error::Result<()> {
if let Err(err) = painter.draw_data(terminal, app) {
- cleanup_terminal(terminal, is_debug)?;
+ cleanup_terminal(terminal)?;
return Err(err);
}
@@ -249,7 +249,6 @@ pub fn try_drawing(
pub fn cleanup_terminal(
terminal: &mut tui::terminal::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>,
- is_debug: bool,
) -> error::Result<()> {
disable_raw_mode()?;
execute!(
@@ -259,11 +258,11 @@ pub fn cleanup_terminal(
)?;
terminal.show_cursor()?;
- if is_debug {
- let mut tmp_dir = std::env::temp_dir();
- tmp_dir.push("bottom_debug.log");
- println!("Your debug file is located at {:?}", tmp_dir.as_os_str());
- }
+ // if is_debug {
+ // let mut tmp_dir = std::env::temp_dir();
+ // tmp_dir.push("bottom_debug.log");
+ // println!("Your debug file is located at {:?}", tmp_dir.as_os_str());
+ // }
Ok(())
}
@@ -448,9 +447,7 @@ fn update_final_process_list(app: &mut App, widget_id: u64) {
fn sort_process_data(
to_sort_vec: &mut Vec<ConvertedProcessData>, proc_widget_state: &app::ProcWidgetState,
) {
- to_sort_vec.sort_by(|a, b| {
- utils::gen_util::get_ordering(&a.name.to_lowercase(), &b.name.to_lowercase(), false)
- });
+ to_sort_vec.sort_by_cached_key(|c| c.name.to_lowercase());
match &proc_widget_state.process_sorting_type {
ProcessSorting::CpuPercent => {
@@ -483,22 +480,18 @@ fn sort_process_data(
ProcessSorting::ProcessName => {
// Don't repeat if false... it sorts by name by default anyways.
if proc_widget_state.is_process_sort_descending {
- to_sort_vec.sort_by(|a, b| {
- utils::gen_util::get_ordering(
- &a.name.to_lowercase(),
- &b.name.to_lowercase(),
- proc_widget_state.is_process_sort_descending,
- )
- })
+ to_sort_vec.sort_by_cached_key(|c| c.name.to_lowercase());
+ if proc_widget_state.is_process_sort_descending {
+ to_sort_vec.reverse();
+ }
+ }
+ }
+ ProcessSorting::Command => {
+ to_sort_vec.sort_by_cached_key(|c| c.command.to_lowercase());
+ if proc_widget_state.is_process_sort_descending {
+ to_sort_vec.reverse();
}
}
- ProcessSorting::Command => to_sort_vec.sort_by(|a, b| {
- utils::gen_util::get_ordering(
- &a.command.to_lowercase(),
- &b.command.to_lowercase(),
- proc_widget_state.is_process_sort_descending,
- )
- }),
ProcessSorting::Pid => {
if !proc_widget_state.is_grouped {
to_sort_vec.sort_by(|a, b| {
@@ -546,13 +539,12 @@ fn sort_process_data(
)
});
}
- ProcessSorting::State => to_sort_vec.sort_by(|a, b| {
- utils::gen_util::get_ordering(
- &a.process_state.to_lowercase(),
- &b.process_state.to_lowercase(),
- proc_widget_state.is_process_sort_descending,
- )
- }),
+ ProcessSorting::State => {
+ to_sort_vec.sort_by_cached_key(|c| c.process_state.to_lowercase());
+ if proc_widget_state.is_process_sort_descending {
+ to_sort_vec.reverse();
+ }
+ }
ProcessSorting::Count => {
if proc_widget_state.is_grouped {
to_sort_vec.sort_by(|a, b| {
@@ -573,9 +565,9 @@ pub fn create_input_thread(
>,
termination_ctrl_lock: Arc<Mutex<bool>>,
) -> std::thread::JoinHandle<()> {
- trace!("Creating input thread.");
+ // trace!("Creating input thread.");
thread::spawn(move || {
- trace!("Spawned input thread.");
+ // trace!("Spawned input thread.");
let mut mouse_timer = Instant::now();
let mut keyboard_timer = Instant::now();
@@ -583,7 +575,7 @@ pub fn create_input_thread(
if let Ok(is_terminated) = termination_ctrl_lock.try_lock() {
// We don't block.
if *is_terminated {
- trace!("Received termination lock in input thread!");
+ // trace!("Received termination lock in input thread!");
drop(is_terminated);
break;
}
@@ -591,13 +583,13 @@ pub fn create_input_thread(
if let Ok(poll) = poll(Duration::from_millis(20)) {
if poll {
if let Ok(event) = read() {
- trace!("Input thread received an event: {:?}", event);
+ // trace!("Input thread received an event: {:?}", event);
if let Event::Key(key) = event {
if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 {
if sender.send(BottomEvent::KeyInput(key)).is_err() {
break;
}
- trace!("Input thread sent keyboard data.");
+ // trace!("Input thread sent keyboard data.");
keyboard_timer = Instant::now();
}
} else if let Event::Mouse(mouse) = event {
@@ -605,7 +597,7 @@ pub fn create_input_thread(
if sender.send(BottomEvent::MouseInput(mouse)).is_err() {
break;
}
- trace!("Input thread sent mouse data.");
+ // trace!("Input thread sent mouse data.");
mouse_timer = Instant::now();
}
}
@@ -613,7 +605,7 @@ pub fn create_input_thread(
}
}
}
- trace!("Input thread loop has closed.");
+ // trace!("Input thread loop has closed.");
})
}
@@ -625,39 +617,39 @@ pub fn create_collection_thread(
termination_ctrl_lock: Arc<Mutex<bool>>, termination_ctrl_cvar: Arc<Condvar>,
app_config_fields: &app::AppConfigFields, used_widget_set: UsedWidgets,
) -> std::thread::JoinHandle<()> {
- trace!("Creating collection thread.");
+ // trace!("Creating collection thread.");
let temp_type = app_config_fields.temperature_type.clone();
let use_current_cpu_total = app_config_fields.use_current_cpu_total;
let show_average_cpu = app_config_fields.show_average_cpu;
let update_rate_in_milliseconds = app_config_fields.update_rate_in_milliseconds;
thread::spawn(move || {
- trace!("Spawned collection thread.");
+ // trace!("Spawned collection thread.");
let mut data_state = data_harvester::DataCollector::default();
- trace!("Created default data state.");
+ // trace!("Created default data state.");
data_state.set_collected_data(used_widget_set);
data_state.set_temperature_type(temp_type);
data_state.set_use_current_cpu_total(use_current_cpu_total);
data_state.set_show_average_cpu(show_average_cpu);
- trace!("Set default data state settings.");
+ // trace!("Set default data state settings.");
data_state.init();
- trace!("Data state is now fully initialized.");
+ // trace!("Data state is now fully initialized.");
loop {
// Check once at the very top...
if let Ok(is_terminated) = termination_ctrl_lock.try_lock() {
// We don't block here.
if *is_terminated {
- trace!("Received termination lock in collection thread!");
+ // trace!("Received termination lock in collection thread!");
drop(is_terminated);
break;
}
}
- trace!("Checking for collection control receiver event...");
+ // trace!("Checking for collection control receiver event...");
let mut update_time = update_rate_in_milliseconds;
if let Ok(message) = control_receiver.try_recv() {
- trace!("Received message in collection thread: {:?}", message);
+ // trace!("Received message in collection thread: {:?}", message);
match message {
ThreadControlEvent::Reset => {
data_state.data.cleanup();
@@ -682,32 +674,32 @@ pub fn create_collection_thread(
if let Ok(is_terminated) = termination_ctrl_lock.try_lock() {
// We don't block here.
if *is_terminated {
- trace!("Received termination lock in collection thread!");
+ // trace!("Received termination lock in collection thread!");
drop(is_terminated);
break;
}
}
- trace!("Collection thread is updating and sending...");
+ // trace!("Collection thread is updating and sending...");
let event = BottomEvent::Update(Box::from(data_state.data));
data_state.data = data_harvester::Data::default();
if sender.send(event).is_err() {
- trace!("Error sending from collection thread...");
+ // trace!("Error sending from collection thread...");
break;
}
- trace!("No problem sending from collection thread!");
+ // trace!("No problem sending from collection thread!");
if let Ok((is_terminated, _wait_timeout_result)) = termination_ctrl_cvar.wait_timeout(
termination_ctrl_lock.lock().unwrap(),
Duration::from_millis(update_time),
) {
if *is_terminated {
- trace!("Received termination lock in collection thread from cvar!");
+ // trace!("Received termination lock in collection thread from cvar!");
drop(is_terminated);
break;
}
}
}
- trace!("Collection thread loop has closed.");
+ // trace!("Collection thread loop has closed.");
})
}