From dcae0a4c2ec2727630a7b9356fd30d467b44b49d Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 20:53:23 +0100 Subject: [PATCH 01/20] use inline format args (clippy::uninlined_format_args) --- src/localize.rs | 2 +- src/main.rs | 10 +++++----- src/terminal_box.rs | 14 ++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/localize.rs b/src/localize.rs index f5c6fb9..012d25f 100644 --- a/src/localize.rs +++ b/src/localize.rs @@ -43,6 +43,6 @@ pub fn localize() { let requested_languages = i18n_embed::DesktopLanguageRequester::requested_languages(); if let Err(error) = localizer.select(&requested_languages) { - eprintln!("Error while loading language for App List {}", error); + eprintln!("Error while loading language for App List {error}"); } } diff --git a/src/main.rs b/src/main.rs index c0a1fb1..ee7935a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ fn main() -> Result<(), Box> { Ok(fork::Fork::Child) => (), Ok(fork::Fork::Parent(_child_pid)) => process::exit(0), Err(err) => { - eprintln!("failed to daemonize: {:?}", err); + eprintln!("failed to daemonize: {err:?}"); process::exit(1); } } @@ -656,7 +656,7 @@ impl App { hash = short_hash.as_str(), date = date )) - .on_press(Message::LaunchUrl(format!("{}/commits/{}", repository, hash))) + .on_press(Message::LaunchUrl(format!("{repository}/commits/{hash}"))) .padding(0) .into(), ]) @@ -1341,7 +1341,7 @@ impl Application for App { let mut font_size_names = Vec::new(); let mut font_sizes = Vec::new(); for font_size in 4..=32 { - font_size_names.push(format!("{}px", font_size)); + font_size_names.push(format!("{font_size}px")); font_sizes.push(font_size); } @@ -1597,7 +1597,7 @@ impl Application for App { Ok(ok) => ok, Err(err) => { self.color_scheme_errors - .push(format!("Failed to open {:?}: {}", path, err)); + .push(format!("Failed to open {path:?}: {err}")); continue; } }; @@ -1616,7 +1616,7 @@ impl Application for App { } Err(err) => { self.color_scheme_errors - .push(format!("Failed to parse {:?}: {}", path, err)); + .push(format!("Failed to parse {path:?}: {err}")); } } } diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 6b26101..48056c4 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -698,8 +698,7 @@ where match named { Named::Backspace => { let code = if modifiers.control() { "\x08" } else { "\x7f" }; - terminal - .input_scroll(format!("{}{}", alt_prefix, code).as_bytes().to_vec()); + terminal.input_scroll(format!("{alt_prefix}{code}").as_bytes().to_vec()); status = Status::Captured; } Named::Enter => { @@ -728,8 +727,7 @@ where } Named::Tab => { let code = if modifiers.shift() { "\x1b[Z" } else { "\x09" }; - terminal - .input_scroll(format!("{}{}", alt_prefix, code).as_bytes().to_vec()); + terminal.input_scroll(format!("{alt_prefix}{code}").as_bytes().to_vec()); status = Status::Captured; } _ => {} @@ -1151,10 +1149,10 @@ fn calculate_modifier_number(state: &mut State) -> u8 { #[inline(always)] fn csi(code: &str, suffix: &str, modifiers: u8) -> Option> { if modifiers == 1 { - Some(format!("\x1B[{}{}", code, suffix).as_bytes().to_vec()) + Some(format!("\x1B[{code}{suffix}").as_bytes().to_vec()) } else { Some( - format!("\x1B[{};{}{}", code, modifiers, suffix) + format!("\x1B[{code};{modifiers}{suffix}") .as_bytes() .to_vec(), ) @@ -1164,8 +1162,8 @@ fn csi(code: &str, suffix: &str, modifiers: u8) -> Option> { #[inline(always)] fn ss3(code: &str, modifiers: u8) -> Option> { if modifiers == 1 { - Some(format!("\x1B\x4F{}", code).as_bytes().to_vec()) + Some(format!("\x1B\x4F{code}").as_bytes().to_vec()) } else { - Some(format!("\x1B[1;{}{}", modifiers, code).as_bytes().to_vec()) + Some(format!("\x1B[1;{modifiers}{code}").as_bytes().to_vec()) } } From 011af310d2873b173fe06937a8fd233a8f4d17f3 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 20:58:19 +0100 Subject: [PATCH 02/20] collapse single match blocks (clippy::single_match, clippy::single_match_else) --- src/main.rs | 103 ++++++++++++++++++++++-------------------------- src/terminal.rs | 18 ++++----- 2 files changed, 57 insertions(+), 64 deletions(-) diff --git a/src/main.rs b/src/main.rs index ee7935a..1ab32de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2326,31 +2326,28 @@ impl Application for App { } // Extra work to do to prepare context pages - match self.context_page { - ContextPage::ColorSchemes(color_scheme_kind) => { - self.color_scheme_errors.clear(); - self.color_scheme_expanded = None; - self.color_scheme_renaming = None; - self.color_scheme_tab_model = widget::segmented_button::Model::default(); - let dark_entity = self - .color_scheme_tab_model - .insert() - .text(fl!("dark")) - .data(ColorSchemeKind::Dark) - .id(); - let light_entity = self - .color_scheme_tab_model - .insert() - .text(fl!("light")) - .data(ColorSchemeKind::Light) - .id(); - self.color_scheme_tab_model - .activate(match color_scheme_kind { - ColorSchemeKind::Dark => dark_entity, - ColorSchemeKind::Light => light_entity, - }); - } - _ => {} + if let ContextPage::ColorSchemes(color_scheme_kind) = self.context_page { + self.color_scheme_errors.clear(); + self.color_scheme_expanded = None; + self.color_scheme_renaming = None; + self.color_scheme_tab_model = widget::segmented_button::Model::default(); + let dark_entity = self + .color_scheme_tab_model + .insert() + .text(fl!("dark")) + .data(ColorSchemeKind::Dark) + .id(); + let light_entity = self + .color_scheme_tab_model + .insert() + .text(fl!("light")) + .data(ColorSchemeKind::Light) + .id(); + self.color_scheme_tab_model + .activate(match color_scheme_kind { + ColorSchemeKind::Dark => dark_entity, + ColorSchemeKind::Light => light_entity, + }); } self.set_context_title(context_page.title()); @@ -2449,38 +2446,32 @@ impl Application for App { .get(&pane) .cloned() .unwrap_or_else(widget::Id::unique); - match tab_model.data::>(entity) { - Some(terminal) => { - let mut terminal_box = terminal_box(terminal) - .id(terminal_id) - .on_context_menu(move |position_opt| { - Message::TabContextMenu(pane, position_opt) - }) - .opacity(self.config.opacity_ratio()) - .padding(space_xxs); + if let Some(terminal) = tab_model.data::>(entity) { + let mut terminal_box = terminal_box(terminal) + .id(terminal_id) + .on_context_menu(move |position_opt| { + Message::TabContextMenu(pane, position_opt) + }) + .opacity(self.config.opacity_ratio()) + .padding(space_xxs); - if self.config.focus_follow_mouse { - terminal_box = - terminal_box.on_mouse_enter(move || Message::MouseEnter(pane)); - } - - let context_menu = { - let terminal = terminal.lock().unwrap(); - terminal.context_menu - }; - - let tab_element: Element<'_, Message> = match context_menu { - Some(point) => widget::popover(terminal_box.context_menu(point)) - .popup(menu::context_menu(&self.config, &self.key_binds, entity)) - .position(widget::popover::Position::Point(point)) - .into(), - None => terminal_box.into(), - }; - tab_column = tab_column.push(tab_element); - } - None => { - //TODO + if self.config.focus_follow_mouse { + terminal_box = terminal_box.on_mouse_enter(move || Message::MouseEnter(pane)); } + + let context_menu = { + let terminal = terminal.lock().unwrap(); + terminal.context_menu + }; + + let tab_element: Element<'_, Message> = match context_menu { + Some(point) => widget::popover(terminal_box.context_menu(point)) + .popup(menu::context_menu(&self.config, &self.key_binds, entity)) + .position(widget::popover::Position::Point(point)) + .into(), + None => terminal_box.into(), + }; + tab_column = tab_column.push(tab_element); } //Only draw find in the currently focused pane @@ -2538,6 +2529,8 @@ impl Application for App { tab_column = tab_column .push(widget::layer_container(find_widget).layer(cosmic_theme::Layer::Primary)); + } else { + // TODO } pane_grid::Content::new(tab_column) diff --git a/src/terminal.rs b/src/terminal.rs index ba72435..b7a5452 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -110,25 +110,25 @@ fn convert_color(colors: &Colors, color: Color) -> cosmic_text::Color { let rgb = match color { Color::Named(named_color) => match colors[named_color] { Some(rgb) => rgb, - None => match named_color { - NamedColor::Background => { + None => { + if named_color == NamedColor::Background { // Allow using an unset background return cosmic_text::Color(WINDOW_BG_COLOR.load(Ordering::SeqCst)); - } - _ => { + } else { log::warn!("missing named color {:?}", named_color); Rgb::default() } - }, + } }, Color::Spec(rgb) => rgb, - Color::Indexed(index) => match colors[index as usize] { - Some(rgb) => rgb, - None => { + Color::Indexed(index) => { + if let Some(rgb) = colors[index as usize] { + rgb + } else { log::warn!("missing indexed color {}", index); Rgb::default() } - }, + } }; cosmic_text::Color::rgb(rgb.r, rgb.g, rgb.b) } From 0811bbe18c53cce6ccb457b4f7904b33ada1c72c Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 21:00:36 +0100 Subject: [PATCH 03/20] replace 'seach-is_some' with 'any' (clippy::search_is_some) --- src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 00c4e65..424859a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -296,7 +296,7 @@ impl Config { let mut name = color_scheme.name.clone(); let mut copies = 1; - while color_scheme_names.iter().find(|x| x.0 == name).is_some() { + while color_scheme_names.iter().any(|x| x.0 == name) { copies += 1; name = format!("{} ({})", color_scheme.name, copies); } @@ -332,7 +332,7 @@ impl Config { let mut name = profile.name.clone(); let mut copies = 1; - while profile_names.iter().find(|x| x.0 == name).is_some() { + while profile_names.iter().any(|x| x.0 == name) { copies += 1; name = format!("{} ({})", profile.name, copies); } From e7e2ac18c8cc47d6943393865d1dffe34fbc0572 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 21:02:01 +0100 Subject: [PATCH 04/20] remove needless 'return' statements (clippy::needless_return) --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1ab32de..f490e85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1260,7 +1260,7 @@ impl App { log::warn!("tried to create new tab before having event channel"); } } - return self.update_title(Some(pane)); + self.update_title(Some(pane)) } } From 4913e084928c7e370a721ea49cb0a9aef3245b85 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 21:03:05 +0100 Subject: [PATCH 05/20] avoid cloning 'copy' types (clippy::clone_on_copy) --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f490e85..6a370f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1524,7 +1524,7 @@ impl Application for App { move |result| { Message::ColorSchemeExportResult( color_scheme_kind, - color_scheme_id.clone(), + color_scheme_id, result, ) }, From 4b7c0ca15a0c33dc7cfef256ed0b7056a792e013 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 21:06:06 +0100 Subject: [PATCH 06/20] avoid manual 'try' statement (clippy::question_mark) --- src/mouse_reporter.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/mouse_reporter.rs b/src/mouse_reporter.rs index e97075b..cca5dc7 100644 --- a/src/mouse_reporter.rs +++ b/src/mouse_reporter.rs @@ -36,7 +36,7 @@ impl MouseReporter { ) -> Option> { //Buttons are handle slightly different between normal and sgr //for normal/utf8 the button release is always reported as button 3 - let Some(mut button) = (match event { + let mut button = (match event { Event::Mouse(MouseEvent::ButtonPressed(b)) => { self.button = Some(b); self.button_number(b) @@ -64,9 +64,7 @@ impl MouseReporter { .map(|b| b + 32) } _ => None, - }) else { - return None; - }; + })?; if modifiers.shift() { button += 4; @@ -127,7 +125,7 @@ impl MouseReporter { x: u32, y: u32, ) -> Option> { - let Some((button_no, event_code)) = (match event { + let (button_no, event_code) = (match event { Event::Mouse(MouseEvent::ButtonPressed(button)) => { //Button pressed is reported as button 0,1,2 and event code M self.button = Some(button); @@ -151,9 +149,7 @@ impl MouseReporter { .map(|button| (self.button_number(button).map(|b| b + 32), "M")) } _ => None, - }) else { - return None; - }; + })?; if let Some(mut button_no) = button_no { if modifiers.shift() { From d3eb8d5ad0b3d390fab5af0ce3e9667fb976a043 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 21:08:03 +0100 Subject: [PATCH 07/20] use 'clamp' function (clippy::manual_clamp) --- src/terminal_box.rs | 2 +- src/terminal_theme.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 48056c4..da6e88b 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -364,7 +364,7 @@ where if !metadata.flags.is_empty() { let style_line_height = - (self.glyph_font_size / 10.0).max(2.0).min(16.0); + (self.glyph_font_size / 10.0).clamp(2.0, 16.0); let line_color = cosmic_text_to_iced_color(metadata.underline_color); diff --git a/src/terminal_theme.rs b/src/terminal_theme.rs index a2e1b80..8df1dff 100644 --- a/src/terminal_theme.rs +++ b/src/terminal_theme.rs @@ -55,8 +55,8 @@ impl ColorDerive { fn color_adj(rgb: Rgb, saturation_adj: f32, lightness_adj: f32) -> Rgb { let mut okhsl = Self::rgb_to_okhsl(rgb); - okhsl.saturation = (okhsl.saturation + saturation_adj).max(0.0).min(1.0); - okhsl.lightness = (okhsl.lightness + lightness_adj).max(0.0).min(1.0); + okhsl.saturation = (okhsl.saturation + saturation_adj).clamp(0.0, 1.0); + okhsl.lightness = (okhsl.lightness + lightness_adj).clamp(0.0, 1.0); Self::okhsl_to_rgb(okhsl) } From de6f48a9511519b98043f8afd35f6ba345a919da Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 21:08:14 +0100 Subject: [PATCH 08/20] fixup --- src/terminal_box.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/terminal_box.rs b/src/terminal_box.rs index da6e88b..aec9eec 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -363,8 +363,7 @@ where } if !metadata.flags.is_empty() { - let style_line_height = - (self.glyph_font_size / 10.0).clamp(2.0, 16.0); + let style_line_height = (self.glyph_font_size / 10.0).clamp(2.0, 16.0); let line_color = cosmic_text_to_iced_color(metadata.underline_color); From 89174c5e0d005bc0582e6deb06269b635f36e5ce Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sun, 14 Apr 2024 21:09:14 +0100 Subject: [PATCH 09/20] use implicit iter loops (clippy::explicit_iter_loop) --- src/config.rs | 4 ++-- src/main.rs | 6 +++--- src/menu.rs | 2 +- src/terminal_box.rs | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 424859a..d6a80e4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -292,7 +292,7 @@ impl Config { let color_schemes = self.color_schemes(color_scheme_kind); let mut color_scheme_names = Vec::<(String, ColorSchemeId)>::with_capacity(color_schemes.len()); - for (color_scheme_id, color_scheme) in color_schemes.iter() { + for (color_scheme_id, color_scheme) in color_schemes { let mut name = color_scheme.name.clone(); let mut copies = 1; @@ -328,7 +328,7 @@ impl Config { // Get a sorted and adjusted for duplicates list of profile names and ids pub fn profile_names(&self) -> Vec<(String, ProfileId)> { let mut profile_names = Vec::<(String, ProfileId)>::with_capacity(self.profiles.len()); - for (profile_id, profile) in self.profiles.iter() { + for (profile_id, profile) in &self.profiles { let mut name = profile.name.clone(); let mut copies = 1; diff --git a/src/main.rs b/src/main.rs index 6a370f1..dc981d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -746,7 +746,7 @@ impl App { .into(), ); - for error in self.color_scheme_errors.iter() { + for error in &self.color_scheme_errors { sections.push( widget::row::with_children(vec![ icon_cache_get("dialog-error-symbolic", 16) @@ -1592,7 +1592,7 @@ impl Application for App { self.dialog_opt = None; if let DialogResult::Open(paths) = result { self.color_scheme_errors.clear(); - for path in paths.iter() { + for path in &paths { let mut file = match fs::File::open(path) { Ok(ok) => ok, Err(err) => { @@ -1831,7 +1831,7 @@ impl Application for App { config_set!(focus_follow_mouse, focus_follow_mouse); } Message::Key(modifiers, key) => { - for (key_bind, action) in self.key_binds.iter() { + for (key_bind, action) in &self.key_binds { if key_bind.matches(modifiers, &key) { return self.update(action.message(None)); } diff --git a/src/menu.rs b/src/menu.rs index a97dd05..301987c 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -26,7 +26,7 @@ pub fn context_menu<'a>( entity: segmented_button::Entity, ) -> Element<'a, Message> { let find_key = |action: &Action| -> String { - for (key_bind, key_action) in key_binds.iter() { + for (key_bind, key_action) in key_binds { if action == key_action { return key_bind.to_string(); } diff --git a/src/terminal_box.rs b/src/terminal_box.rs index aec9eec..f2f4661 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -165,7 +165,7 @@ where // Calculate layout lines terminal.with_buffer(|buffer| { let mut layout_lines = 0; - for line in buffer.lines.iter() { + for line in &buffer.lines { match line.layout_opt() { Some(layout) => layout_lines += layout.len(), None => (), @@ -480,7 +480,7 @@ where view_position, metadata_set, }; - for glyph in run.glyphs.iter() { + for glyph in run.glyphs { bg_rect.update(glyph, renderer, state.is_focused); } bg_rect.fill(renderer, state.is_focused); @@ -598,7 +598,7 @@ where modifiers, .. }) if state.is_focused => { - for (key_bind, _) in self.key_binds.iter() { + for (key_bind, _) in &self.key_binds { if key_bind.matches(modifiers, &Key::Named(named)) { return Status::Captured; } @@ -741,7 +741,7 @@ where key, .. }) if state.is_focused => { - for (key_bind, _) in self.key_binds.iter() { + for (key_bind, _) in &self.key_binds { if key_bind.matches(modifiers, &key) { return Status::Captured; } From f8c23b2ef14851e2e14bfcd5007590392d0b6f0a Mon Sep 17 00:00:00 2001 From: "daniel.eades" Date: Mon, 15 Apr 2024 16:29:02 +0100 Subject: [PATCH 10/20] remove needless mut (clippy::needless_pass_by_ref_mut) --- src/terminal_box.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/terminal_box.rs b/src/terminal_box.rs index f2f4661..55dc44e 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -1128,7 +1128,7 @@ meta 0b100000 (32) caps_lock 0b1000000 (64) num_lock 0b10000000 (128) */ -fn calculate_modifier_number(state: &mut State) -> u8 { +fn calculate_modifier_number(state: &State) -> u8 { let mut mod_no = 0; if state.modifiers.shift() { mod_no |= 1; From e3a0d8c6dd9bc135b1bc7ea7105a052811a72e5b Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 20:37:44 +0100 Subject: [PATCH 11/20] use dedicated method for iterating over map keys (clippy::for_kv_map) --- src/terminal_box.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 55dc44e..70cb854 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -598,7 +598,7 @@ where modifiers, .. }) if state.is_focused => { - for (key_bind, _) in &self.key_binds { + for key_bind in self.key_binds.keys() { if key_bind.matches(modifiers, &Key::Named(named)) { return Status::Captured; } @@ -741,7 +741,7 @@ where key, .. }) if state.is_focused => { - for (key_bind, _) in &self.key_binds { + for key_bind in self.key_binds.keys() { if key_bind.matches(modifiers, &key) { return Status::Captured; } From 76d166b26635d030aff01c633ba415c443389329 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 20:44:25 +0100 Subject: [PATCH 12/20] prefer lossless conversion to cast (clippy::cast_lossless) --- src/config.rs | 2 +- src/main.rs | 10 +++++----- src/terminal_box.rs | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index d6a80e4..ffc2a61 100644 --- a/src/config.rs +++ b/src/config.rs @@ -322,7 +322,7 @@ impl Config { } pub fn opacity_ratio(&self) -> f32 { - (self.opacity as f32) / 100.0 + f32::from(self.opacity) / 100.0 } // Get a sorted and adjusted for duplicates list of profile names and ids diff --git a/src/main.rs b/src/main.rs index dc981d8..7662314 100644 --- a/src/main.rs +++ b/src/main.rs @@ -452,9 +452,9 @@ impl App { { let color = Color::from(theme.cosmic().background.base); let bytes = color.into_rgba8(); - let data = (bytes[2] as u32) - | ((bytes[1] as u32) << 8) - | ((bytes[0] as u32) << 16) + let data = u32::from(bytes[2]) + | (u32::from(bytes[1]) << 8) + | (u32::from(bytes[0]) << 16) | 0xFF000000; terminal::WINDOW_BG_COLOR.store(data, Ordering::SeqCst); } @@ -938,8 +938,8 @@ impl App { let padding = Padding { top: 0.0, bottom: 0.0, - left: space_s as f32, - right: space_s as f32, + left: space_s.into(), + right: space_s.into(), }; profiles_section = profiles_section.add(widget::container(expanded_section).padding(padding)) diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 70cb854..f4bcc7e 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -234,7 +234,7 @@ where let state = tree.state.downcast_ref::(); let cosmic_theme = theme.cosmic(); - let scrollbar_w = cosmic_theme.spacing.space_xxs as f32; + let scrollbar_w = f32::from(cosmic_theme.spacing.space_xxs); let view_position = layout.position() + [self.padding.left, self.padding.top].into(); let view_w = cmp::min(viewport.width as i32, layout.bounds().width as i32) @@ -271,12 +271,12 @@ where ..Default::default() }, Color::new( - background_color.r() as f32 / 255.0, - background_color.g() as f32 / 255.0, - background_color.b() as f32 / 255.0, + f32::from(background_color.r()) / 255.0, + f32::from(background_color.g()) / 255.0, + f32::from(background_color.b()) / 255.0, match self.opacity { Some(opacity) => opacity, - None => background_color.a() as f32 / 255.0, + None => f32::from(background_color.a()) / 255.0, }, ), ); @@ -322,10 +322,10 @@ where ) { let cosmic_text_to_iced_color = |color: cosmic_text::Color| { Color::new( - color.r() as f32 / 255.0, - color.g() as f32 / 255.0, - color.b() as f32 / 255.0, - color.a() as f32 / 255.0, + f32::from(color.r()) / 255.0, + f32::from(color.g()) / 255.0, + f32::from(color.b()) / 255.0, + f32::from(color.a()) / 255.0, ) }; @@ -1050,9 +1050,9 @@ fn shade(color: cosmic_text::Color, is_focused: bool) -> cosmic_text::Color { } else { let shade = 0.92; cosmic_text::Color::rgba( - (color.r() as f32 * shade) as u8, - (color.g() as f32 * shade) as u8, - (color.b() as f32 * shade) as u8, + (f32::from(color.r()) * shade) as u8, + (f32::from(color.g()) * shade) as u8, + (f32::from(color.b()) * shade) as u8, color.a(), ) } From 34cf7bf76a2a0185b532819538982ff32a3f7750 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 20:47:12 +0100 Subject: [PATCH 13/20] use 'let/else' syntax (clippy::manual_let_else) --- src/main.rs | 5 ++--- src/terminal.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7662314..5a98350 100644 --- a/src/main.rs +++ b/src/main.rs @@ -789,9 +789,8 @@ impl App { if !self.config.profiles.is_empty() { let mut profiles_section = widget::settings::view_section(""); for (profile_name, profile_id) in self.config.profile_names() { - let profile = match self.config.profiles.get(&profile_id) { - Some(some) => some, - None => continue, + let Some(profile) = self.config.profiles.get(&profile_id) else { + continue; }; let expanded = self.profile_expanded == Some(profile_id); diff --git a/src/terminal.rs b/src/terminal.rs index b7a5452..af004bb 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -437,9 +437,8 @@ impl Terminal { } } - let search_regex = match &mut self.search_regex_opt { - Some(some) => some, - None => return, + let Some(search_regex) = &mut self.search_regex_opt else { + return; }; // Determine search origin From ec5c2a1991554a2ebb951119a52931b140f49931 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 20:49:03 +0100 Subject: [PATCH 14/20] flip boolean block (clippy::if_not_else) --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5a98350..4bb2b78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1201,10 +1201,10 @@ impl App { hold: profile.hold, env: HashMap::new(), }; - let tab_title_override = if !profile.tab_title.is_empty() { - Some(profile.tab_title.clone()) - } else { + let tab_title_override = if profile.tab_title.is_empty() { None + } else { + Some(profile.tab_title.clone()) }; (options, tab_title_override) } @@ -1455,10 +1455,10 @@ impl Application for App { } fn on_context_drawer(&mut self) -> Command { - if !self.core.window.show_context { - self.update_focus() - } else { + if self.core.window.show_context { Command::none() + } else { + self.update_focus() } } From 9544ba9397f38870bb624f68a95ee2f80771c2ab Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 20:52:07 +0100 Subject: [PATCH 15/20] remove needless borrows (clippy::needless_borrows_for_generic_args) --- src/main.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4bb2b78..e51cbfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -491,17 +491,14 @@ impl App { fn save_color_schemes(&mut self, color_scheme_kind: ColorSchemeKind) -> Command { // Optimized for just saving color_schemes if let Some(ref config_handler) = self.config_handler { - match config_handler.set( + if let Err(err) = config_handler.set( match color_scheme_kind { ColorSchemeKind::Dark => "color_schemes_dark", ColorSchemeKind::Light => "color_schemes_light", }, - &self.config.color_schemes(color_scheme_kind), + self.config.color_schemes(color_scheme_kind), ) { - Ok(()) => {} - Err(err) => { - log::error!("failed to save config: {}", err); - } + log::error!("failed to save config: {}", err); } } self.update_color_schemes(); @@ -1547,9 +1544,8 @@ impl Application for App { &color_scheme, ron::ser::PrettyConfig::new(), ) { - Ok(ron) => match fs::write(path, &ron) { - Ok(()) => {} - Err(err) => { + Ok(ron) => { + if let Err(err) = fs::write(path, ron) { log::error!( "failed to export {:?} to {:?}: {}", color_scheme_id, @@ -1557,7 +1553,7 @@ impl Application for App { err ); } - }, + } Err(err) => { log::error!( "failed to serialize color scheme {:?}: {}", From cfa00871284597b3b5ce4844c6be873e05898ddb Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 20:54:27 +0100 Subject: [PATCH 16/20] remove no-op if statement (clippy::needless_if) --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e51cbfc..ab6ae8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1181,7 +1181,6 @@ impl App { .and_then(|profile_id| self.config.profiles.get(&profile_id)) { Some(profile) => { - if !profile.tab_title.is_empty() {} let mut shell = None; if let Some(mut args) = shlex::split(&profile.command) { if !args.is_empty() { From 1eb1bd4caafb1681f1b15a4d46157b2566a8eb92 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 21:04:46 +0100 Subject: [PATCH 17/20] minor refactoring --- src/main.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index ab6ae8c..7c20ba3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1465,15 +1465,10 @@ impl Application for App { ($name: ident, $value: expr) => { match &self.config_handler { Some(config_handler) => { - match paste::paste! { self.config.[](config_handler, $value) } { - Ok(_) => {} - Err(err) => { - log::warn!( - "failed to save config {:?}: {}", - stringify!($name), - err - ); - } + if let Err(err) = + paste::paste! { self.config.[](config_handler, $value) } + { + log::warn!("failed to save config {:?}: {}", stringify!($name), err); } } None => { @@ -1831,12 +1826,11 @@ impl Application for App { } } } - Message::LaunchUrl(url) => match open::that_detached(&url) { - Ok(()) => {} - Err(err) => { + Message::LaunchUrl(url) => { + if let Err(err) = open::that_detached(&url) { log::warn!("failed to open {:?}: {}", url, err); } - }, + } Message::Modifiers(modifiers) => { self.modifiers = modifiers; } From 1b53309d6324b1cb695ca785356a22d3eac32bb0 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 21:05:30 +0100 Subject: [PATCH 18/20] use 'Self' keyword to refer to own type (clippy::use_self) --- src/main.rs | 72 ++++++++++++++++++++++----------------------- src/terminal_box.rs | 4 +-- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7c20ba3..5225872 100644 --- a/src/main.rs +++ b/src/main.rs @@ -206,43 +206,43 @@ impl MenuAction for Action { fn message(&self, entity_opt: Option) -> Message { match self { - Action::About => Message::ToggleContextPage(ContextPage::About), - Action::ColorSchemes(color_scheme_kind) => { + Self::About => Message::ToggleContextPage(ContextPage::About), + Self::ColorSchemes(color_scheme_kind) => { Message::ToggleContextPage(ContextPage::ColorSchemes(*color_scheme_kind)) } - Action::Copy => Message::Copy(entity_opt), - Action::Find => Message::Find(true), - Action::PaneFocusDown => Message::PaneFocusAdjacent(pane_grid::Direction::Down), - Action::PaneFocusLeft => Message::PaneFocusAdjacent(pane_grid::Direction::Left), - Action::PaneFocusRight => Message::PaneFocusAdjacent(pane_grid::Direction::Right), - Action::PaneFocusUp => Message::PaneFocusAdjacent(pane_grid::Direction::Up), - Action::PaneSplitHorizontal => Message::PaneSplit(pane_grid::Axis::Horizontal), - Action::PaneSplitVertical => Message::PaneSplit(pane_grid::Axis::Vertical), - Action::PaneToggleMaximized => Message::PaneToggleMaximized, - Action::Paste => Message::Paste(entity_opt), - Action::ProfileOpen(profile_id) => Message::ProfileOpen(*profile_id), - Action::Profiles => Message::ToggleContextPage(ContextPage::Profiles), - Action::SelectAll => Message::SelectAll(entity_opt), - Action::Settings => Message::ToggleContextPage(ContextPage::Settings), - Action::ShowHeaderBar(show_headerbar) => Message::ShowHeaderBar(*show_headerbar), - Action::TabActivate0 => Message::TabActivateJump(0), - Action::TabActivate1 => Message::TabActivateJump(1), - Action::TabActivate2 => Message::TabActivateJump(2), - Action::TabActivate3 => Message::TabActivateJump(3), - Action::TabActivate4 => Message::TabActivateJump(4), - Action::TabActivate5 => Message::TabActivateJump(5), - Action::TabActivate6 => Message::TabActivateJump(6), - Action::TabActivate7 => Message::TabActivateJump(7), - Action::TabActivate8 => Message::TabActivateJump(8), - Action::TabClose => Message::TabClose(entity_opt), - Action::TabNew => Message::TabNew, - Action::TabNext => Message::TabNext, - Action::TabPrev => Message::TabPrev, - Action::WindowClose => Message::WindowClose, - Action::WindowNew => Message::WindowNew, - Action::ZoomIn => Message::ZoomIn, - Action::ZoomOut => Message::ZoomOut, - Action::ZoomReset => Message::ZoomReset, + Self::Copy => Message::Copy(entity_opt), + Self::Find => Message::Find(true), + Self::PaneFocusDown => Message::PaneFocusAdjacent(pane_grid::Direction::Down), + Self::PaneFocusLeft => Message::PaneFocusAdjacent(pane_grid::Direction::Left), + Self::PaneFocusRight => Message::PaneFocusAdjacent(pane_grid::Direction::Right), + Self::PaneFocusUp => Message::PaneFocusAdjacent(pane_grid::Direction::Up), + Self::PaneSplitHorizontal => Message::PaneSplit(pane_grid::Axis::Horizontal), + Self::PaneSplitVertical => Message::PaneSplit(pane_grid::Axis::Vertical), + Self::PaneToggleMaximized => Message::PaneToggleMaximized, + Self::Paste => Message::Paste(entity_opt), + Self::ProfileOpen(profile_id) => Message::ProfileOpen(*profile_id), + Self::Profiles => Message::ToggleContextPage(ContextPage::Profiles), + Self::SelectAll => Message::SelectAll(entity_opt), + Self::Settings => Message::ToggleContextPage(ContextPage::Settings), + Self::ShowHeaderBar(show_headerbar) => Message::ShowHeaderBar(*show_headerbar), + Self::TabActivate0 => Message::TabActivateJump(0), + Self::TabActivate1 => Message::TabActivateJump(1), + Self::TabActivate2 => Message::TabActivateJump(2), + Self::TabActivate3 => Message::TabActivateJump(3), + Self::TabActivate4 => Message::TabActivateJump(4), + Self::TabActivate5 => Message::TabActivateJump(5), + Self::TabActivate6 => Message::TabActivateJump(6), + Self::TabActivate7 => Message::TabActivateJump(7), + Self::TabActivate8 => Message::TabActivateJump(8), + Self::TabClose => Message::TabClose(entity_opt), + Self::TabNew => Message::TabNew, + Self::TabNext => Message::TabNext, + Self::TabPrev => Message::TabPrev, + Self::WindowClose => Message::WindowClose, + Self::WindowNew => Message::WindowNew, + Self::ZoomIn => Message::ZoomIn, + Self::ZoomOut => Message::ZoomOut, + Self::ZoomReset => Message::ZoomReset, } } } @@ -1387,7 +1387,7 @@ impl Application for App { let mut terminal_ids = HashMap::new(); terminal_ids.insert(pane_model.focus, widget::Id::unique()); - let mut app = App { + let mut app = Self { core, pane_model, config_handler: flags.config_handler, diff --git a/src/terminal_box.rs b/src/terminal_box.rs index f4bcc7e..8e1703c 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -1092,8 +1092,8 @@ pub struct State { impl State { /// Creates a new [`State`]. - pub fn new() -> State { - State { + pub fn new() -> Self { + Self { modifiers: Modifiers::empty(), click: None, dragging: None, From 5f0a0ba7260cd196e170bdefa970536e113a1c99 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 21:10:32 +0100 Subject: [PATCH 19/20] remove unused 'self' (clippy::unused_self) --- src/mouse_reporter.rs | 16 ++++++---------- src/terminal.rs | 4 ++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mouse_reporter.rs b/src/mouse_reporter.rs index cca5dc7..40ec38f 100644 --- a/src/mouse_reporter.rs +++ b/src/mouse_reporter.rs @@ -15,7 +15,7 @@ pub struct MouseReporter { } impl MouseReporter { - fn button_number(&self, button: Button) -> Option { + fn button_number(button: Button) -> Option { match button { Button::Left => Some(0), Button::Middle => Some(1), @@ -39,7 +39,7 @@ impl MouseReporter { let mut button = (match event { Event::Mouse(MouseEvent::ButtonPressed(b)) => { self.button = Some(b); - self.button_number(b) + Self::button_number(b) } Event::Mouse(MouseEvent::ButtonReleased(_b)) => { self.button = None; @@ -59,9 +59,7 @@ impl MouseReporter { //character, Cb). //For example, motion into cell x,y with button 1 down is reported as //CSI M @ CxCy ( @ = 32 + 0 (button 1) + 32 (motion indicator) ). - self.button - .and_then(|button| self.button_number(button)) - .map(|b| b + 32) + self.button.and_then(Self::button_number).map(|b| b + 32) } _ => None, })?; @@ -129,12 +127,12 @@ impl MouseReporter { Event::Mouse(MouseEvent::ButtonPressed(button)) => { //Button pressed is reported as button 0,1,2 and event code M self.button = Some(button); - Some((self.button_number(button), "M")) + Some((Self::button_number(button), "M")) } Event::Mouse(MouseEvent::ButtonReleased(button)) => { //Button pressed is reported as button 0,1,2 and event code m self.button = None; - Some((self.button_number(button), "m")) + Some((Self::button_number(button), "m")) } Event::Mouse(MouseEvent::CursorMoved { .. }) => { //Button pressed is reported as button 32 + 0,1,2 and event code M @@ -146,7 +144,7 @@ impl MouseReporter { self.last_movment_y = Some(y); } self.button - .map(|button| (self.button_number(button).map(|b| b + 32), "M")) + .map(|button| (Self::button_number(button).map(|b| b + 32), "M")) } _ => None, })?; @@ -170,7 +168,6 @@ impl MouseReporter { #[allow(clippy::too_many_arguments)] pub fn report_sgr_mouse_wheel_scroll( - &self, terminal: &Terminal, term_cell_width: f32, term_cell_height: f32, @@ -213,7 +210,6 @@ impl MouseReporter { //Emulate mouse wheel scroll with up/down arrows. Using mouse spec uses //scroll-back and scroll-forw actions, which moves whole windows like page up/page down. pub fn report_mouse_wheel_as_arrows( - &self, terminal: &Terminal, term_cell_width: f32, term_cell_height: f32, diff --git a/src/terminal.rs b/src/terminal.rs index af004bb..fb6c6a0 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -855,7 +855,7 @@ impl Terminal { let term_lock = self.term.lock(); let mode = term_lock.mode(); if mode.contains(TermMode::SGR_MOUSE) { - self.mouse_reporter.report_sgr_mouse_wheel_scroll( + MouseReporter::report_sgr_mouse_wheel_scroll( self, self.size().cell_width, self.size().cell_height, @@ -865,7 +865,7 @@ impl Terminal { y, ); } else { - self.mouse_reporter.report_mouse_wheel_as_arrows( + MouseReporter::report_mouse_wheel_as_arrows( self, self.size().cell_width, self.size().cell_height, From 3ccfa4509d0f3bb2e9f133b9f394876728084a98 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 15 Apr 2024 21:15:30 +0100 Subject: [PATCH 20/20] minor refactoring --- src/terminal_box.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/terminal_box.rs b/src/terminal_box.rs index 8e1703c..60e849c 100644 --- a/src/terminal_box.rs +++ b/src/terminal_box.rs @@ -166,9 +166,8 @@ where terminal.with_buffer(|buffer| { let mut layout_lines = 0; for line in &buffer.lines { - match line.layout_opt() { - Some(layout) => layout_lines += layout.len(), - None => (), + if let Some(layout) = line.layout_opt() { + layout_lines += layout.len() } }