mirror of
https://github.com/ClementTsang/bottom.git
synced 2024-11-03 21:04:38 +03:00
refactor: clippy and small cleanup/comments (#865)
* refactor: small cleanup and comments in some code * clippy * more clippy * fixes for macos/freebsd
This commit is contained in:
parent
d56b551e39
commit
76c3bc4254
2
build.rs
2
build.rs
@ -8,7 +8,7 @@ use std::{
|
||||
include!("src/clap.rs");
|
||||
|
||||
fn create_dir(dir: &Path) -> Result<()> {
|
||||
let res = fs::create_dir_all(&dir);
|
||||
let res = fs::create_dir_all(dir);
|
||||
match &res {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
|
20
src/app.rs
20
src/app.rs
@ -839,7 +839,7 @@ impl App {
|
||||
&self.current_widget.top_left_corner,
|
||||
&self.current_widget.bottom_right_corner,
|
||||
) {
|
||||
let border_offset = if self.is_drawing_border() { 1 } else { 0 };
|
||||
let border_offset = u16::from(self.is_drawing_border());
|
||||
let header_offset = self.header_offset(&self.current_widget);
|
||||
let height = brc_y - tlc_y - 2 * border_offset - header_offset;
|
||||
self.change_position_count(-(height as i64));
|
||||
@ -867,7 +867,7 @@ impl App {
|
||||
&self.current_widget.top_left_corner,
|
||||
&self.current_widget.bottom_right_corner,
|
||||
) {
|
||||
let border_offset = if self.is_drawing_border() { 1 } else { 0 };
|
||||
let border_offset = u16::from(self.is_drawing_border());
|
||||
let header_offset = self.header_offset(&self.current_widget);
|
||||
let height = brc_y - tlc_y - 2 * border_offset - header_offset;
|
||||
self.change_position_count(height as i64);
|
||||
@ -886,7 +886,7 @@ impl App {
|
||||
&self.current_widget.top_left_corner,
|
||||
&self.current_widget.bottom_right_corner,
|
||||
) {
|
||||
let border_offset = if self.is_drawing_border() { 1 } else { 0 };
|
||||
let border_offset = u16::from(self.is_drawing_border());
|
||||
let header_offset = self.header_offset(&self.current_widget);
|
||||
let height = brc_y - tlc_y - 2 * border_offset - header_offset;
|
||||
self.change_position_count(-(height as i64) / 2);
|
||||
@ -905,7 +905,7 @@ impl App {
|
||||
&self.current_widget.top_left_corner,
|
||||
&self.current_widget.bottom_right_corner,
|
||||
) {
|
||||
let border_offset = if self.is_drawing_border() { 1 } else { 0 };
|
||||
let border_offset = u16::from(self.is_drawing_border());
|
||||
let header_offset = self.header_offset(&self.current_widget);
|
||||
let height = brc_y - tlc_y - 2 * border_offset - header_offset;
|
||||
self.change_position_count(height as i64 / 2);
|
||||
@ -1330,13 +1330,13 @@ impl App {
|
||||
|
||||
pub fn kill_highlighted_process(&mut self) -> Result<()> {
|
||||
if let BottomWidgetType::Proc = self.current_widget.widget_type {
|
||||
if let Some(current_selected_processes) = &self.to_delete_process_list {
|
||||
if let Some((_, pids)) = &self.to_delete_process_list {
|
||||
#[cfg(target_family = "unix")]
|
||||
let signal = match self.delete_dialog_state.selected_signal {
|
||||
KillSignal::Kill(sig) => sig,
|
||||
KillSignal::Cancel => 15, // should never happen, so just TERM
|
||||
};
|
||||
for pid in ¤t_selected_processes.1 {
|
||||
for pid in pids {
|
||||
#[cfg(target_family = "unix")]
|
||||
{
|
||||
process_killer::kill_process_given_pid(*pid, signal)?;
|
||||
@ -2456,7 +2456,7 @@ impl App {
|
||||
&self.current_widget.top_left_corner,
|
||||
&self.current_widget.bottom_right_corner,
|
||||
) {
|
||||
let border_offset = if self.is_drawing_border() { 1 } else { 0 };
|
||||
let border_offset = u16::from(self.is_drawing_border());
|
||||
|
||||
// This check ensures the click isn't actually just clicking on the bottom border.
|
||||
if y < (brc_y - border_offset) {
|
||||
@ -2616,11 +2616,7 @@ impl App {
|
||||
1 + self.app_config_fields.table_gap
|
||||
} else {
|
||||
let min_height_for_header = if self.is_drawing_border() { 3 } else { 1 };
|
||||
if height_diff > min_height_for_header {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
u16::from(height_diff > min_height_for_header)
|
||||
}
|
||||
} else {
|
||||
1 + self.app_config_fields.table_gap
|
||||
|
@ -99,7 +99,7 @@ fn matches_ignore_list(filter_check_map: &[(&Option<Filter>, &String)]) -> bool
|
||||
|
||||
fn get_disk_info() -> io::Result<StorageSystemInformation> {
|
||||
let output = std::process::Command::new("df")
|
||||
.args(&["--libxo", "json", "-k", "-t", "ufs,msdosfs,zfs"])
|
||||
.args(["--libxo", "json", "-k", "-t", "ufs,msdosfs,zfs"])
|
||||
.output()?;
|
||||
deserialize_xo("storage-system-information", &output.stdout)
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ fn get_freebsd_process_cpu_usage(pids: &[i32]) -> io::Result<std::collections::H
|
||||
}
|
||||
|
||||
let output = std::process::Command::new("ps")
|
||||
.args(&["--libxo", "json", "-o", "pid,pcpu", "-p"])
|
||||
.args(["--libxo", "json", "-o", "pid,pcpu", "-p"])
|
||||
.args(pids.iter().map(i32::to_string))
|
||||
.output()?;
|
||||
deserialize_xo("process-information", &output.stdout).map(|process_info: ProcessInformation| {
|
||||
|
@ -29,7 +29,7 @@ fn get_macos_process_cpu_usage(
|
||||
) -> std::io::Result<std::collections::HashMap<i32, f64>> {
|
||||
use itertools::Itertools;
|
||||
let output = std::process::Command::new("ps")
|
||||
.args(&["-o", "pid=,pcpu=", "-p"])
|
||||
.args(["-o", "pid=,pcpu=", "-p"])
|
||||
.arg(
|
||||
// Has to look like this since otherwise, it you hit a `unstable_name_collisions` warning.
|
||||
Itertools::intersperse(pids.iter().map(i32::to_string), ",".to_string())
|
||||
|
@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow, collections::hash_map::Entry};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::{
|
||||
app::{
|
||||
@ -499,7 +499,7 @@ impl ProcWidget {
|
||||
|
||||
let mut id_pid_map: FxHashMap<String, Vec<Pid>> = FxHashMap::default();
|
||||
let mut filtered_data: Vec<ProcWidgetData> = if let ProcWidgetMode::Grouped = self.mode {
|
||||
let mut id_process_mapping: FxHashMap<String, ProcessHarvest> = FxHashMap::default();
|
||||
let mut id_process_mapping: FxHashMap<&String, ProcessHarvest> = FxHashMap::default();
|
||||
for process in filtered_iter {
|
||||
let id = if is_using_command {
|
||||
&process.command
|
||||
@ -508,19 +508,17 @@ impl ProcWidget {
|
||||
};
|
||||
let pid = process.pid;
|
||||
|
||||
match id_pid_map.entry(id.clone()) {
|
||||
Entry::Occupied(mut occupied) => {
|
||||
occupied.get_mut().push(pid);
|
||||
}
|
||||
Entry::Vacant(vacant) => {
|
||||
vacant.insert(vec![pid]);
|
||||
}
|
||||
if let Some(entry) = id_pid_map.get_mut(id) {
|
||||
entry.push(pid);
|
||||
} else {
|
||||
id_pid_map.insert(id.clone(), vec![pid]);
|
||||
}
|
||||
|
||||
if let Some(grouped_process_harvest) = id_process_mapping.get_mut(id) {
|
||||
grouped_process_harvest.add(process);
|
||||
} else {
|
||||
id_process_mapping.insert(id.clone(), process.clone());
|
||||
// FIXME: [PERF] could maybe eliminate an allocation here in the grouped mode... or maybe just avoid the entire transformation step, making an alloc fine.
|
||||
id_process_mapping.insert(id, process.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,19 +100,19 @@ impl CanvasColours {
|
||||
match colour_scheme {
|
||||
ColourScheme::Default => {}
|
||||
ColourScheme::DefaultLight => {
|
||||
canvas_colours.set_colours_from_palette(&*DEFAULT_LIGHT_MODE_COLOUR_PALETTE)?;
|
||||
canvas_colours.set_colours_from_palette(&DEFAULT_LIGHT_MODE_COLOUR_PALETTE)?;
|
||||
}
|
||||
ColourScheme::Gruvbox => {
|
||||
canvas_colours.set_colours_from_palette(&*GRUVBOX_COLOUR_PALETTE)?;
|
||||
canvas_colours.set_colours_from_palette(&GRUVBOX_COLOUR_PALETTE)?;
|
||||
}
|
||||
ColourScheme::GruvboxLight => {
|
||||
canvas_colours.set_colours_from_palette(&*GRUVBOX_LIGHT_COLOUR_PALETTE)?;
|
||||
canvas_colours.set_colours_from_palette(&GRUVBOX_LIGHT_COLOUR_PALETTE)?;
|
||||
}
|
||||
ColourScheme::Nord => {
|
||||
canvas_colours.set_colours_from_palette(&*NORD_COLOUR_PALETTE)?;
|
||||
canvas_colours.set_colours_from_palette(&NORD_COLOUR_PALETTE)?;
|
||||
}
|
||||
ColourScheme::NordLight => {
|
||||
canvas_colours.set_colours_from_palette(&*NORD_LIGHT_COLOUR_PALETTE)?;
|
||||
canvas_colours.set_colours_from_palette(&NORD_LIGHT_COLOUR_PALETTE)?;
|
||||
}
|
||||
ColourScheme::Custom => {
|
||||
if let Some(colors) = &config.colors {
|
||||
|
@ -230,7 +230,7 @@ pub fn build_app() -> Command<'static> {
|
||||
.long("color")
|
||||
.takes_value(true)
|
||||
.value_name("COLOR SCHEME")
|
||||
.possible_values(&[
|
||||
.possible_values([
|
||||
"default",
|
||||
"default-light",
|
||||
"gruvbox",
|
||||
|
@ -194,7 +194,7 @@ where
|
||||
}
|
||||
|
||||
let show_header = inner_height > 1;
|
||||
let header_height = if show_header { 1 } else { 0 };
|
||||
let header_height = u16::from(show_header);
|
||||
let table_gap = if !show_header || draw_loc.height < TABLE_GAP_HEIGHT_LIMIT {
|
||||
0
|
||||
} else {
|
||||
|
@ -336,7 +336,6 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
|
Loading…
Reference in New Issue
Block a user