diff options
author | Canop <cano.petrole@gmail.com> | 2023-02-04 21:53:39 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2023-02-04 21:53:39 +0100 |
commit | afc07e46d0973b0ff199df3fc2e27fcde89d1e37 (patch) | |
tree | d16c8a11f972eb664fb2e69d2100acbae5c373df | |
parent | b00b2efb93416463cfaf11e378274b0051745ef9 (diff) |
clippy...
47 files changed, 128 insertions, 160 deletions
diff --git a/benches/fuzzy.rs b/benches/fuzzy.rs index b4b0748..4e55601 100644 --- a/benches/fuzzy.rs +++ b/benches/fuzzy.rs @@ -9,7 +9,7 @@ static PATTERNS: &[&str] = &["réveil", "AB", "e", "brt", "brootz"]; fn bench_score_of_fuzzy(gb: &mut Bench) { for pattern in PATTERNS { - let task_name = format!("Fuzzy({:?})::score_of", pattern); + let task_name = format!("Fuzzy({pattern:?})::score_of"); gb.task(task_name, |b| { let fp = FuzzyPattern::from(pattern); b.iter(|| { diff --git a/benches/toks.rs b/benches/toks.rs index eba448d..fe00eec 100644 --- a/benches/toks.rs +++ b/benches/toks.rs @@ -9,7 +9,7 @@ static PATTERNS: &[&str] = &["a", "réveil", "bro,c", "e,jenc,arec,ehro", "broot fn bench_score_of_toks(gb: &mut Bench) { for pattern in PATTERNS { - let task_name = format!("TokPattern({:?})::score_of", pattern); + let task_name = format!("TokPattern({pattern:?})::score_of"); gb.task(task_name, |b| { let fp = TokPattern::new(pattern); b.iter(|| { @@ -33,7 +33,7 @@ fn build_completion_scripts() { write_completions_file(Shell::Fish, &out_dir); write_completions_file(Shell::PowerShell, &out_dir); write_completions_file(Shell::Zsh, &out_dir); - eprintln!("completion scripts generated in {:?}", out_dir); + eprintln!("completion scripts generated in {out_dir:?}"); } fn main() { diff --git a/src/app/app_context.rs b/src/app/app_context.rs index 00beab5..cdfe189 100644 --- a/src/app/app_context.rs +++ b/src/app/app_context.rs @@ -122,7 +122,7 @@ impl AppContext { .map_err(ConfError::from)?; let file_sum_threads_count = config.file_sum_threads_count .unwrap_or(file_sum::DEFAULT_THREAD_COUNT); - if file_sum_threads_count < 1 || file_sum_threads_count > 50 { + if !(1..=50).contains(&file_sum_threads_count) { return Err(ConfError::InvalidThreadsCount{ count: file_sum_threads_count }.into()); } let max_panels_count = config.max_panels_count diff --git a/src/app/panel.rs b/src/app/panel.rs index 4455c27..c1d1d76 100644 --- a/src/app/panel.rs +++ b/src/app/panel.rs @@ -158,7 +158,7 @@ impl Panel { let mut command_parts = CommandParts::from(self.input.get_content()); if command_parts.verb_invocation.is_some() { command_parts.verb_invocation = None; - let new_input = format!("{}", command_parts); + let new_input = format!("{command_parts}"); self.input.set_content(&new_input); } self.mut_state().set_mode(initial_mode(con)); @@ -177,7 +177,7 @@ impl Panel { let mut command_parts = CommandParts::from(self.input.get_content()); if let Some(invocation) = &mut command_parts.verb_invocation { invocation.args = Some(arg); - let new_input = format!("{}", command_parts); + let new_input = format!("{command_parts}"); self.input.set_content(&new_input); } } @@ -263,7 +263,7 @@ impl Panel { .next() .unwrap_or_else(|| ":start_end_panel".to_string()); - let md = format!("hit *{}* to fill arg ", shortcut); + let md = format!("hit *{shortcut}* to fill arg "); // Add verbindex in purpose ? screen.goto(w, area.left, area.top)?; panel_skin.purpose_skin.write_composite_fill( diff --git a/src/app/panel_state.rs b/src/app/panel_state.rs index b6a1a78..9a0d82d 100644 --- a/src/app/panel_state.rs +++ b/src/app/panel_state.rs @@ -156,7 +156,7 @@ pub trait PanelState { CmdResult::new_state(Box::new(state)) } } - Err(e) => CmdResult::DisplayError(format!("{}", e)), + Err(e) => CmdResult::DisplayError(format!("{e}")), } } Internal::help => { @@ -745,7 +745,7 @@ pub trait PanelState { Command::PatternEdit { raw, expr } => { match InputPattern::new(raw.clone(), expr, con) { Ok(pattern) => self.on_pattern(pattern, app_state, con), - Err(e) => Ok(CmdResult::DisplayError(format!("{}", e))), + Err(e) => Ok(CmdResult::DisplayError(format!("{e}"))), } } Command::VerbTrigger { @@ -809,31 +809,27 @@ pub trait PanelState { validate_purpose: false, panel_ref: PanelReference::Id(id), } + } else if prefered_mode.is_some() { + // we'll make the preview mode change be + // applied on the preview panel + CmdResult::ApplyOnPanel { id } } else { - if prefered_mode.is_some() { - // we'll make the preview mode change be - // applied on the preview panel - CmdResult::ApplyOnPanel { id } - } else { - CmdResult::Keep - } + CmdResult::Keep + } + } else if let Some(path) = self.selected_path() { + CmdResult::NewPanel { + state: Box::new(PreviewState::new( + path.to_path_buf(), + InputPattern::none(), + prefered_mode, + self.tree_options(), + cc.app.con, + )), + purpose: PanelPurpose::Preview, + direction: HDir::Right, } } else { - if let Some(path) = self.selected_path() { - CmdResult::NewPanel { - state: Box::new(PreviewState::new( - path.to_path_buf(), - InputPattern::none(), - prefered_mode, - self.tree_options(), - cc.app.con, - )), - purpose: PanelPurpose::Preview, - direction: HDir::Right, - } - } else { - CmdResult::error("no selected file") - } + CmdResult::error("no selected file") } } @@ -953,7 +949,7 @@ pub trait PanelState { "Possible verbs: {}", completions .iter() - .map(|c| format!("*{}*", c)) + .map(|c| format!("*{c}*")) .collect::<Vec<String>>() .join(", "), ), diff --git a/src/app/selection.rs b/src/app/selection.rs index 2fb56b7..b6aa358 100644 --- a/src/app/selection.rs +++ b/src/app/selection.rs @@ -80,7 +80,7 @@ impl Selection<'_> { if let Some(export_path) = &con.launch_args.outcmd { // broot was launched as br, we can launch the executable from the shell let f = OpenOptions::new().append(true).open(export_path)?; - writeln!(&f, "{}", path)?; + writeln!(&f, "{path}")?; CmdResult::Quit } else { CmdResult::from(Launchable::program( diff --git a/src/app/standard_status.rs b/src/app/standard_status.rs index 1c15e8a..be7fa3e 100644 --- a/src/app/standard_status.rs +++ b/src/app/standard_status.rs @@ -33,32 +33,32 @@ impl StandardStatus { let tree_dir_focus = "*enter* to focus".to_string(); let tree_dir_cd = verb_store .key_desc_of_internal_stype(Internal::open_leave, SelectionType::Directory) - .map(|k| format!("*{}* to cd", k)); + .map(|k| format!("*{k}* to cd")); let tree_file_open_stay = verb_store .key_desc_of_internal_stype(Internal::open_stay, SelectionType::File) - .map(|k| format!("*{}* to open the file", k)); + .map(|k| format!("*{k}* to open the file")); let tree_file_open_leave = verb_store .key_desc_of_internal_stype(Internal::open_leave, SelectionType::File) - .map(|k| format!("*{}* to open and quit", k)); + .map(|k| format!("*{k}* to open and quit")); //let tree_file_enter = None; // TODO (for when enter is customized) let tree_unfiltered = "a few letters to search".to_string(); let tree_filtered = "*esc* to clear the filter".to_string(); let preview_unfiltered = "a pattern to filter".to_string(); let preview_filtered = verb_store .key_desc_of_internal(Internal::panel_right) - .map(|k| format!("*{}* to reveal the text", k)); + .map(|k| format!("*{k}* to reveal the text")); let preview_restorable_filter = verb_store .key_desc_of_internal(Internal::panel_left_no_open) - .map(|k| format!("*{}* to restore the filter", k)); + .map(|k| format!("*{k}* to restore the filter")); let not_first_state = "*esc* to go back".to_string(); let help = "*?* for help".to_string(); let no_verb = "a space then a verb".to_string(); let all_files_hidden = verb_store .key_desc_of_internal(Internal::toggle_hidden) - .map(|k| format!("Some files are hidden, use *{}* to display them", k)); + .map(|k| format!("Some files are hidden, use *{k}* to display them")); let all_files_git_ignored = verb_store .key_desc_of_internal(Internal::toggle_git_ignore) - .map(|k| format!("Some files are git-ignored, use *{}* to display them", k)); + .map(|k| format!("Some files are git-ignored, use *{k}* to display them")); Self { tree_top_focus, tree_dir_focus, diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs index 8d6a455..2002024 100644 --- a/src/browser/browser_state.rs +++ b/src/browser/browser_state.rs @@ -158,7 +158,7 @@ impl BrowserState { info!("open returned with exit_status {:?}", exit_status); Ok(CmdResult::Keep) } - Err(e) => Ok(CmdResult::error(format!("{:?}", e))), + Err(e) => Ok(CmdResult::error(format!("{e:?}"))), } } } @@ -436,7 +436,7 @@ impl PanelState for BrowserState { } Internal::page_up => { let tree = self.displayed_tree_mut(); - if !tree.try_scroll(page_height as i32 * -1, page_height) { + if !tree.try_scroll(-(page_height as i32), page_height) { tree.try_select_first(); } CmdResult::Keep @@ -501,7 +501,7 @@ impl PanelState for BrowserState { con, ) } else { - CmdResult::error(format!("{:?} has no parent", root)) + CmdResult::error(format!("{root:?} has no parent")) } } Internal::root_down => { @@ -615,18 +615,16 @@ impl PanelState for BrowserState { con: &AppContext, ) -> Status { let tree = self.displayed_tree(); - if tree.is_empty() { - if tree.build_report.hidden_count > 0 { - let mut parts = Vec::new(); - if let Some(md) = con.standard_status.all_files_hidden.clone() { - parts.push(md); - } - if let Some(md) = con.standard_status.all_files_git_ignored.clone() { - parts.push(md); - } - if !parts.is_empty() { - return Status::from_error(parts.join(". ")); - } + if tree.is_empty() && tree.build_report.hidden_count > 0 { + let mut parts = Vec::new(); + if let Some(md) = con.standard_status.all_files_hidden.clone() { + parts.push(md); + } + if let Some(md) = con.standard_status.all_files_git_ignored.clone() { + parts.push(md); + } + if !parts.is_empty() { + return Status::from_error(parts.join(". ")); } } let mut ssb = con.standard_status.builder( diff --git a/src/cli/args.rs b/src/cli/args.rs index 2c0768a..ab32ebf 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -209,7 +209,7 @@ impl FromStr for CliShellInstallState { "installed" => Ok(Self::Installed), _ => Err( // not supposed to happen because claps check the values - format!("unexpected install state: {:?}", state) + format!("unexpected install state: {state:?}") ), } } diff --git a/src/command/panel_input.rs b/src/command/panel_input.rs index 192645c..1558f26 100644 --- a/src/command/panel_input.rs +++ b/src/command/panel_input.rs @@ -364,10 +364,8 @@ impl PanelInput { } // input field management - if mode == Mode::Input { - if self.input_field.apply_timed_event(timed_event) { - return Command::from_raw(self.input_field.get_content(), false); - } + if mode == Mode::Input && self.input_field.apply_timed_event(timed_event) { + return Command::from_raw(self.input_field.get_content(), false); } Command::None } diff --git a/src/command/parts.rs b/src/command/parts.rs index 6dc2559..a69de49 100644 --- a/src/command/parts.rs +++ b/src/command/parts.rs @@ -19,7 +19,7 @@ impl fmt::Display for CommandParts { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.raw_pattern)?; if let Some(invocation) = &self.verb_invocation { - write!(f, "{}", invocation)?; + write!(f, "{invocation}")?; } Ok(()) } @@ -171,7 +171,7 @@ mod test_command_parts { let right = CommandParts { raw_pattern: raw_pattern.to_string(), pattern, - verb_invocation: verb_invocation.map(|s| VerbInvocation::from(s)), + verb_invocation: verb_invocation.map(VerbInvocation::from), }; dbg!(&right); assert_eq!(left, right); diff --git a/src/conf/default.rs b/src/conf/default.rs index 93a87e2..d4b4209 100644 --- a/src/conf/default.rs +++ b/src/conf/default.rs @@ -15,7 +15,7 @@ pub fn write_default_conf_in(dir: &Path) -> Result<(), io::Error> { if !dir.is_dir() { return Err(io::Error::new( io::ErrorKind::Other, - format!("{:?} isn't a directory", dir), + format!("{dir:?} isn't a directory"), )); } } else { diff --git a/src/conf/verb_conf.rs b/src/conf/verb_conf.rs index 87107d2..ca9844f 100644 --- a/src/conf/verb_conf.rs +++ b/src/conf/verb_conf.rs @@ -170,7 +170,7 @@ impl VerbConf { None => SelectionType::Any, Some(s) => { return Err(ConfError::InvalidVerbConf { - details: format!("{:?} isn't a valid value of apply_to", s), + details: format!("{s:?} isn't a valid value of apply_to"), }); } }; diff --git a/src/display/col.rs b/src/display/col.rs index e9eb594..9cc1fcc 100644 --- a/src/display/col.rs +++ b/src/display/col.rs @@ -89,7 +89,7 @@ impl FromStr for Col { "staged" => Ok(Self::Staged), "n" | "name" => Ok(Self::Name), _ => Err(ConfError::InvalidCols { - details: format!("column not recognized : {}", s), + details: format!("column not recognized : {s}"), }), } } @@ -161,7 +161,7 @@ pub fn parse_cols(arr: &Vec<String>) -> Result<Cols, ConfError> { for (idx, s) in arr.iter().enumerate() { if idx >= COLS_COUNT { return Err(ConfError::InvalidCols { - details: format!("too long: {:?}", arr), + details: format!("too long: {arr:?}"), }); } // we swap the cols, to ensure both keeps being present diff --git a/src/display/displayable_tree.rs b/src/display/displayable_tree.rs index 1a92f4b..6eda9c6 100644 --- a/src/display/displayable_tree.rs +++ b/src/display/displayable_tree.rs @@ -185,7 +185,7 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> { sparse_style, if s.is_sparse() && line.is_file() { 's' } else { ' ' }, )?; - cw.queue_g_string(label_style, format!("{:<10}", pb))?; + cw.queue_g_string(label_style, format!("{pb:<10}"))?; 1 } else { 16 @@ -258,12 +258,10 @@ impl<'a, 's, 't> DisplayableTree<'a, 's, 't> { } else { "│ " } + } else if staged { + "└◍─" } else { - if staged { - "└◍─" - } else { - "└──" - } + "└──" } } else { " " diff --git a/src/display/status_line.rs b/src/display/status_line.rs index edb261c..155143b 100644 --- a/src/display/status_line.rs +++ b/src/display/status_line.rs @@ -24,7 +24,7 @@ pub fn write( screen.goto(w, area.left, y)?; let mut x = area.left; if let Some(pending_task) = task { - let pending_task = format!(" {}… ", pending_task); + let pending_task = format!(" {pending_task}… "); x += pending_task.chars().count() as u16; panel_skin.styles.status_job.queue(w, pending_task)?; } diff --git a/src/errors.rs b/src/errors.rs index eb475b9..a373137 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -43,12 +43,7 @@ impl ShellInstallError { Self::Io { source, .. } => { if source.kind() == io::ErrorKind::PermissionDenied { true - } else if cfg!(windows) && source.raw_os_error().unwrap_or(0) == 1314 { - // https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699- - true - } else { - false - } + } else { cfg!(windows) && source.raw_os_error().unwrap_or(0) == 1314 } } } } diff --git a/src/filesystems/filesystems_state.rs b/src/filesystems/filesystems_state.rs index b125268..0d7d555 100644 --- a/src/filesystems/filesystems_state.rs +++ b/src/filesystems/filesystems_state.rs @@ -420,7 +420,7 @@ impl PanelState for FilesystemState { let pb = ProgressBar::new(stats.use_share() as f32, w_use_bar); let mut bar_style = styles.default.clone(); bar_style.set_bg(share_color); - cw.queue_g_string(&bar_style, format!("{:<width$}", pb, width=w_use_bar))?; + cw.queue_g_string(&bar_style, format!("{pb:<w_use_bar$}"))?; } cw.queue_char(border_style, '│')?; } diff --git a/src/filesystems/mount_space_display.rs b/src/filesystems/mount_space_display.rs index 0b1ce81..be6c583 100644 --- a/src/filesystems/mount_space_display.rs +++ b/src/filesystems/mount_space_display.rs @@ -112,7 +112,7 @@ impl<'m, 's> MountSpaceDisplay<'m, 's> { } cw.queue_unstyled_char(' ')?; cw.w.queue(SetBackgroundColor(share_color))?; - cw.queue_unstyled_g_string(format!("{:<width$}", pb, width = w_bar))?; + cw.queue_unstyled_g_string(format!("{pb:<w_bar$}"))?; } if let Some(bg_color) = bg { cw.w.queue(SetBackgroundColor(bg_color))?; diff --git a/src/help/help_state.rs b/src/help/help_state.rs index d37941f..dbf4e5b 100644 --- a/src/help/help_state.rs +++ b/src/help/help_state.rs @@ -237,7 +237,7 @@ impl PanelState for HelpState { info!("open returned with exit_status {:?}", exit_status); CmdResult::Keep } - Err(e) => CmdResult::DisplayError(format!("{:?}", e)), + Err(e) => CmdResult::DisplayError(format!("{e:?}")), }, // FIXME check we can't use the generic one open_leave => { diff --git a/src/hex/hex_view.rs b/src/hex/hex_view.rs index d2edf98..3c554a1 100644 --- a/src/hex/hex_view.rs +++ b/src/hex/hex_view.rs @@ -163,12 +163,12 @@ impl HexView { cw.queue_g_string( &styles.preview_line_number, match (addresses_len, margin_around_adresses) { - (4, false) => format!("{:04x}", addr), - (6, false) => format!("{:06x}", addr), - (_, false) => format!("{:08x}", addr), - (4, true) => format!(" {:04x} ", addr), - (6, true) => format!(" {:06x} ", addr), - (_, true) => format!(" {:08x} ", addr), + (4, false) => format!("{addr:04x}"), + (6, false) => format!("{addr:06x}"), + (_, false) => format!("{addr:08x}"), + (4, true) => format!(" {addr:04x} "), + (6, true) => format!(" {addr:06x} "), + (_, true) => format!(" {addr:08x} "), }, )?; } @@ -183,9 +183,9 @@ impl HexView { if let Some(b) = line.bytes.get(x) { let byte = Byte::from(*b); if inter_hex { - cw.queue_g_string(byte.style(styles), format!("{:02x} ", b))?; + cw.queue_g_string(byte.style(styles), format!("{b:02x} "))?; } else { - cw.queue_g_string(byte.style(styles), format!("{:02x}", b))?; + cw.queue_g_string(byte.style(styles), format!("{b:02x}"))?; } } else { cw.queue_str(&styles.default, if inter_hex { " " } else { " " })?; @@ -228,9 +228,9 @@ impl HexView { return Ok(()); } if s.len() + " bytes".len() < width { - s = format!("{} bytes", s); + s = format!("{s} bytes"); } else if s.len() + 1 < width { - s = format!("{}b", s); + s = format!("{s}b"); } w.queue(cursor::MoveTo( area.left + area.width - s.len() as u16, diff --git a/src/kitty/mod.rs b/src/kitty/mod.rs index ab71564..5b9527f 100644 --- a/src/kitty/mod.rs +++ b/src/kitty/mod.rs @@ -125,7 +125,7 @@ impl KittyManager { } else { let id = image.image_id; debug!("erase kitty image {}", id); - write!(w, "\u{1b}_Ga=d,d=I,i={}\u{1b}\\", id)?; + write!(w, "\u{1b}_Ga=d,d=I,i={id}\u{1b}\\")?; } } self.rendered_images = kept_images; diff --git a/src/launchable.rs b/src/launchable.rs index e8b24d0..01d0145 100644 --- a/src/launchable.rs +++ b/src/launchable.rs @@ -122,7 +122,7 @@ impl Launchable { ) -> Result<(), ProgramError> { match self { Launchable::Printer { to_print } => { - println!("{}", to_print); + println!("{to_print}"); Ok(()) } Launchable::TreePrinter { tree, skin, ext_colors, width, height } => { |