diff --git a/local/recipes/tui/tlc/source/src/editor/cursor.rs b/local/recipes/tui/tlc/source/src/editor/cursor.rs index 77aa82f00d..90e737a440 100644 --- a/local/recipes/tui/tlc/source/src/editor/cursor.rs +++ b/local/recipes/tui/tlc/source/src/editor/cursor.rs @@ -32,18 +32,15 @@ use crate::editor::buffer::Buffer; /// (line, column) corner and extending to another (line, column) /// corner. Matches Alt+Arrow (MC `MarkColumn*` bindings). #[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Default)] pub enum SelectionMode { /// Contiguous text range — the legacy "Shift+Arrow" behaviour. + #[default] Stream, /// Rectangular block — Alt+Arrow / Alt-PageUp / Alt-PageDown. Column, } -impl Default for SelectionMode { - fn default() -> Self { - Self::Stream - } -} /// A rectangular column selection: `(start_line, start_col, /// end_line, end_col)` in **visual** (tab-expanded) column coordinates. @@ -261,11 +258,9 @@ impl Cursor { // Build the post-delete text by walking line-by-line and // stripping the rectangle columns from each line. let mut new_text = String::with_capacity(text.len()); - let mut byte_pos = 0usize; for line in 0..buf.line_count() { let line_start = buf.line_offset(line); let line_len = buf.line_length(line); - let _ = byte_pos; if line > 0 { new_text.push('\n'); } diff --git a/local/recipes/tui/tlc/source/src/editor/menubar.rs b/local/recipes/tui/tlc/source/src/editor/menubar.rs index f7d84b76d2..2f372a7066 100644 --- a/local/recipes/tui/tlc/source/src/editor/menubar.rs +++ b/local/recipes/tui/tlc/source/src/editor/menubar.rs @@ -359,12 +359,12 @@ impl EditorMenuBar { self.active_menu -= 1; } self.selected_item = 0; - return Handled; + Handled } RIGHT => { self.active_menu = (self.active_menu + 1) % self.menus.len(); self.selected_item = 0; - return Handled; + Handled } UP => { let items = &self.menus[self.active_menu].items; @@ -378,7 +378,7 @@ impl EditorMenuBar { break; } } - return Handled; + Handled } DOWN => { let items = &self.menus[self.active_menu].items; @@ -388,16 +388,17 @@ impl EditorMenuBar { break; } } - return Handled; + Handled } c if c == Key::ENTER.code => { let menu = &self.menus[self.active_menu]; let item = &menu.items[self.selected_item]; let cmd = item.cmd; if matches!(cmd, EditorCmd::Nop) { - return Handled; + Handled + } else { + Dispatch(cmd) } - return Dispatch(cmd); } _ => { if let Some(ch) = Self::key_to_char(key) { @@ -422,10 +423,8 @@ impl EditorMenuBar { /// Decode a printable ASCII letter from a Key (if any). Returns /// `None` for non-letter keys. fn key_to_char(key: Key) -> Option { - if key.code >= 0x20 && key.code <= 0x7E { - if key.mods.is_empty() { - return Some(key.code as u8 as char); - } + if key.code >= 0x20 && key.code <= 0x7E && key.mods.is_empty() { + return Some(key.code as u8 as char); } None } diff --git a/local/recipes/tui/tlc/source/src/editor/mod.rs b/local/recipes/tui/tlc/source/src/editor/mod.rs index d1a4ff35a7..e6cd288a43 100644 --- a/local/recipes/tui/tlc/source/src/editor/mod.rs +++ b/local/recipes/tui/tlc/source/src/editor/mod.rs @@ -649,21 +649,25 @@ bracket_flash: None, self.word_wrap } + /// Whether auto-indent is enabled on Enter. #[must_use] pub fn auto_indent(&self) -> bool { self.auto_indent } + /// Toggle auto-indent and return the new state. pub fn toggle_auto_indent(&mut self) -> bool { self.auto_indent = !self.auto_indent; self.auto_indent } + /// Whether whitespace glyphs are visible. #[must_use] pub fn show_whitespace(&self) -> bool { self.show_whitespace } + /// Toggle whitespace visibility and return the new state. pub fn toggle_show_whitespace(&mut self) -> bool { self.show_whitespace = !self.show_whitespace; self.show_whitespace @@ -1174,8 +1178,8 @@ bracket_flash: None, for line in segment.split_inclusive('\n') { let content = line.strip_suffix('\n').unwrap_or(line); let nl = if line.ends_with('\n') { "\n" } else { "" }; - if content.starts_with('\t') { - new_segment.push_str(&content[1..]); + if let Some(stripped) = content.strip_prefix('\t') { + new_segment.push_str(stripped); removed += 1; } else { let spaces = content.bytes().take_while(|&b| b == b' ').count().min(8); diff --git a/local/recipes/tui/tlc/source/src/editor/render.rs b/local/recipes/tui/tlc/source/src/editor/render.rs index b982833010..8ede38ed0e 100644 --- a/local/recipes/tui/tlc/source/src/editor/render.rs +++ b/local/recipes/tui/tlc/source/src/editor/render.rs @@ -207,11 +207,7 @@ impl Editor { if cursor_line == line_idx { format!("{:>w$}", n, w = (gutter_w - 1) as usize) } else { - let d = if line_idx < cursor_line { - cursor_line - line_idx - } else { - line_idx - cursor_line - }; + let d = line_idx.abs_diff(cursor_line); format!("{:>w$}", d, w = (gutter_w - 1) as usize) } } else { @@ -437,7 +433,7 @@ impl Editor { let popup_h = (window_end - scroll_offset) as u16 + 2; let popup_w = body_area.width.min(40); let row_y = cursor_pos.map(|(_, y)| y).unwrap_or(body_area.y); - let desired_y = if row_y.saturating_sub(body_area.y) >= popup_h + 1 { + let desired_y = if row_y.saturating_sub(body_area.y) > popup_h { row_y - popup_h } else { row_y + 1 @@ -808,6 +804,7 @@ impl Editor { } } +#[allow(clippy::too_many_arguments)] fn paint_scrollbar( buf: &mut ratatui::buffer::Buffer, area: Rect, @@ -888,6 +885,7 @@ fn paint_cursor_shape( } } +#[allow(clippy::too_many_arguments)] fn push_rendered_text<'a>( spans: &mut Vec>, text: &str, @@ -1048,9 +1046,7 @@ fn build_wrap_map( let chars = buffer.line_length_chars(line_idx); // Empty line is always at least one visual row so the user // sees the `~` tilde marker. - let rows = if body_width == 0 { - 1 - } else if chars == 0 { + let rows = if body_width == 0 || chars == 0 { 1 } else { chars.div_ceil(body_width).max(1) diff --git a/local/recipes/tui/tlc/source/src/editor/search.rs b/local/recipes/tui/tlc/source/src/editor/search.rs index a93e23b715..b425e82ba3 100644 --- a/local/recipes/tui/tlc/source/src/editor/search.rs +++ b/local/recipes/tui/tlc/source/src/editor/search.rs @@ -260,7 +260,7 @@ impl SearchState { len, ) { Some(m) => { - let next = if m.len() == 0 { pos + 1 } else { m.range.end }; + let next = if m.is_empty() { pos + 1 } else { m.range.end }; out.push(m); pos = next; } diff --git a/local/recipes/tui/tlc/source/src/filemanager/confirm_dialog.rs b/local/recipes/tui/tlc/source/src/filemanager/confirm_dialog.rs index 2981e1f0c3..37e8246f16 100644 --- a/local/recipes/tui/tlc/source/src/filemanager/confirm_dialog.rs +++ b/local/recipes/tui/tlc/source/src/filemanager/confirm_dialog.rs @@ -3,7 +3,7 @@ use crate::key::Key; use crate::terminal::color::Theme; use ratatui::layout::{Alignment, Constraint, Layout, Rect}; -use ratatui::style::{Modifier, Style}; +use ratatui::style::Style; use ratatui::text::{Line, Span}; use ratatui::widgets::Paragraph; use ratatui::Frame; diff --git a/local/recipes/tui/tlc/source/src/filemanager/connection_dialog.rs b/local/recipes/tui/tlc/source/src/filemanager/connection_dialog.rs index f6b0641d2c..508f477907 100644 --- a/local/recipes/tui/tlc/source/src/filemanager/connection_dialog.rs +++ b/local/recipes/tui/tlc/source/src/filemanager/connection_dialog.rs @@ -17,7 +17,7 @@ use std::path::PathBuf; use ratatui::layout::{Constraint, Direction, Layout, Rect}; -use ratatui::style::{Modifier, Style}; +use ratatui::style::Style; use ratatui::text::{Line, Span}; use ratatui::widgets::Paragraph; use ratatui::Frame; diff --git a/local/recipes/tui/tlc/source/src/filemanager/menubar.rs b/local/recipes/tui/tlc/source/src/filemanager/menubar.rs index b817d59478..dac2b55e74 100644 --- a/local/recipes/tui/tlc/source/src/filemanager/menubar.rs +++ b/local/recipes/tui/tlc/source/src/filemanager/menubar.rs @@ -7,7 +7,7 @@ use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect}; use ratatui::style::{Modifier, Style}; use ratatui::text::{Line, Span}; -use ratatui::widgets::{Block, Borders, Clear, Paragraph}; +use ratatui::widgets::{Clear, Paragraph}; use ratatui::Frame; use crate::key::Key; @@ -356,7 +356,7 @@ impl MenuBar { let y = 1u16; let dropdown_area = Rect::new(x, y, dropdown_w, dropdown_h); - let inner = render_popup(frame, dropdown_area, menu.title.clone(), theme); + let inner = render_popup(frame, dropdown_area, menu.title, theme); let chunks = Layout::default() .direction(Direction::Vertical) diff --git a/local/recipes/tui/tlc/source/src/filemanager/owner.rs b/local/recipes/tui/tlc/source/src/filemanager/owner.rs index 5bffd2605f..3284b6f78b 100644 --- a/local/recipes/tui/tlc/source/src/filemanager/owner.rs +++ b/local/recipes/tui/tlc/source/src/filemanager/owner.rs @@ -12,7 +12,7 @@ use std::path::PathBuf; use ratatui::layout::{Constraint, Direction, Layout, Rect}; -use ratatui::style::{Modifier, Style}; +use ratatui::style::Style; use ratatui::text::{Line, Span}; use ratatui::widgets::{Paragraph, Wrap}; use ratatui::Frame; @@ -241,6 +241,7 @@ impl OwnerDialog { } } +#[allow(dead_code)] fn centered_rect(area: Rect, width_pct: f32, height_pct: f32) -> Rect { let w = (area.width as f32 * width_pct.clamp(0.1, 1.0)) as u16; let h = (area.height as f32 * height_pct.clamp(0.1, 1.0)) as u16; diff --git a/local/recipes/tui/tlc/source/src/filemanager/panel.rs b/local/recipes/tui/tlc/source/src/filemanager/panel.rs index e7b39311ba..10c17179b3 100644 --- a/local/recipes/tui/tlc/source/src/filemanager/panel.rs +++ b/local/recipes/tui/tlc/source/src/filemanager/panel.rs @@ -359,16 +359,19 @@ impl Panel { /// Current sort-reverse state. #[must_use] + /// Whether reverse sort is enabled. pub fn sort_reverse(&self) -> bool { self.sort_reverse } + /// Toggle case-sensitive sort and re-sort. pub fn toggle_sort_case(&mut self) { self.sort_case_sensitive = !self.sort_case_sensitive; self.sort_in_place(); } #[must_use] + /// Whether case-sensitive sort is enabled. pub fn sort_case_sensitive(&self) -> bool { self.sort_case_sensitive } @@ -385,10 +388,12 @@ impl Panel { } #[must_use] + /// Current sort field. pub fn sort_field(&self) -> SortField { self.sort_field } + /// Apply a sort field and direction. pub fn apply_sort(&mut self, field: SortField, reverse: bool) { self.sort_field = field; self.sort_reverse = reverse; diff --git a/local/recipes/tui/tlc/source/src/filemanager/pattern_dialog.rs b/local/recipes/tui/tlc/source/src/filemanager/pattern_dialog.rs index bf57f38e91..ee92b0ecef 100644 --- a/local/recipes/tui/tlc/source/src/filemanager/pattern_dialog.rs +++ b/local/recipes/tui/tlc/source/src/filemanager/pattern_dialog.rs @@ -4,9 +4,9 @@ //! the pattern is returned; on Esc the dialog is cancelled. use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect}; -use ratatui::style::{Modifier, Style}; +use ratatui::style::Style; use ratatui::text::{Line, Span}; -use ratatui::widgets::{Block, Borders, Clear, Paragraph}; +use ratatui::widgets::Paragraph; use ratatui::Frame; use crate::key::Key; diff --git a/local/recipes/tui/tlc/source/src/filemanager/permission.rs b/local/recipes/tui/tlc/source/src/filemanager/permission.rs index c994f2eafc..116cb0113c 100644 --- a/local/recipes/tui/tlc/source/src/filemanager/permission.rs +++ b/local/recipes/tui/tlc/source/src/filemanager/permission.rs @@ -337,6 +337,7 @@ impl PermissionDialog { } } +#[allow(dead_code)] fn centered_rect(area: Rect, width_pct: f32, height_pct: f32) -> Rect { let w = (area.width as f32 * width_pct.clamp(0.1, 1.0)) as u16; let h = (area.height as f32 * height_pct.clamp(0.1, 1.0)) as u16; diff --git a/local/recipes/tui/tlc/source/src/ops/mod.rs b/local/recipes/tui/tlc/source/src/ops/mod.rs index 1b0c09f13b..4d546eb583 100644 --- a/local/recipes/tui/tlc/source/src/ops/mod.rs +++ b/local/recipes/tui/tlc/source/src/ops/mod.rs @@ -168,6 +168,7 @@ pub struct HardlinkTracker { impl HardlinkTracker { #[must_use] + /// Create an empty hardlink tracker. pub fn new() -> Self { Self::default() } diff --git a/local/recipes/tui/tlc/source/src/ops/progress.rs b/local/recipes/tui/tlc/source/src/ops/progress.rs index eb632380c5..cb403f5af4 100644 --- a/local/recipes/tui/tlc/source/src/ops/progress.rs +++ b/local/recipes/tui/tlc/source/src/ops/progress.rs @@ -163,6 +163,7 @@ impl Default for ProgressDialog { } } +#[allow(dead_code)] fn centered_rect(area: Rect, width_pct: f32, height_pct: f32) -> Rect { let w = (area.width as f32 * width_pct.clamp(0.1, 1.0)) as u16; let h = (area.height as f32 * height_pct.clamp(0.1, 1.0)) as u16; diff --git a/local/recipes/tui/tlc/source/src/terminal/color.rs b/local/recipes/tui/tlc/source/src/terminal/color.rs index b66dd833f4..1389b95c41 100644 --- a/local/recipes/tui/tlc/source/src/terminal/color.rs +++ b/local/recipes/tui/tlc/source/src/terminal/color.rs @@ -38,6 +38,7 @@ use ratatui::style::Color; use super::mc_skin; /// Construct a [`Color::Rgb`] from a hex constant at compile time. +#[allow(dead_code)] const fn rgb(r: u8, g: u8, b: u8) -> Color { Color::Rgb(r, g, b) } diff --git a/local/recipes/tui/tlc/source/src/terminal/mc_skin.rs b/local/recipes/tui/tlc/source/src/terminal/mc_skin.rs index 6402952b79..097dd60f4c 100644 --- a/local/recipes/tui/tlc/source/src/terminal/mc_skin.rs +++ b/local/recipes/tui/tlc/source/src/terminal/mc_skin.rs @@ -129,10 +129,10 @@ fn parse_theme(name: &'static str, text: &str) -> Theme { let core_shadow = resolve_style(&parsed, "core", "shadow"); let status = resolve_style(&parsed, "statusbar", "_default_"); let button = resolve_style(&parsed, "buttonbar", "button"); - let button_hotkey = resolve_style(&parsed, "buttonbar", "hotkey"); + let _button_hotkey = resolve_style(&parsed, "buttonbar", "hotkey"); let error = resolve_style(&parsed, "error", "_default_"); let error_title = resolve_style(&parsed, "error", "errdtitle"); - let dialog_default = resolve_style(&parsed, "dialog", "_default_"); + let _dialog_default = resolve_style(&parsed, "dialog", "_default_"); let dialog_focus = resolve_style(&parsed, "dialog", "dfocus"); let file_directory = resolve_style(&parsed, "filehighlight", "directory"); let file_executable = resolve_style(&parsed, "filehighlight", "executable"); diff --git a/local/recipes/tui/tlc/source/src/terminal/popup.rs b/local/recipes/tui/tlc/source/src/terminal/popup.rs index 2ee0fba4f5..ebb63726af 100644 --- a/local/recipes/tui/tlc/source/src/terminal/popup.rs +++ b/local/recipes/tui/tlc/source/src/terminal/popup.rs @@ -3,7 +3,7 @@ use ratatui::buffer::Buffer; use ratatui::layout::Rect; use ratatui::style::{Modifier, Style}; -use ratatui::text::{Line, Span}; +use ratatui::text::Span; use ratatui::widgets::{Block, BorderType, Borders, Clear}; use ratatui::Frame; @@ -64,14 +64,14 @@ fn render_drop_shadow(buf: &mut Buffer, area: Rect, shadow_color: ratatui::style let x = area.x; let rows = area.height as usize; let cols = area.width as usize; - let right_cols = 2.min(buf.area().width.saturating_sub(x as u16 + area.width) as usize); + let right_cols = 2.min(buf.area().width.saturating_sub(x + area.width) as usize); if right_cols == 0 && y + area.height >= buf.area().height { return; } for row in 0..rows.saturating_sub(1) { let yy = y as usize + 1 + row; for col in 0..right_cols { - let xx = x as usize + cols as usize + col; + let xx = x as usize + cols + col; if let Some(cell) = buf.cell_mut((xx as u16, yy as u16)) { cell.set_bg(shadow_color); } @@ -79,7 +79,7 @@ fn render_drop_shadow(buf: &mut Buffer, area: Rect, shadow_color: ratatui::style } let bottom_y = y as usize + rows; if bottom_y < buf.area().height as usize { - let available_cols = buf.area().width.saturating_sub(x as u16 + 2) as usize; + let available_cols = buf.area().width.saturating_sub(x + 2) as usize; let strip_cols = cols.min(available_cols); for col in 0..strip_cols { let xx = x as usize + 2 + col; diff --git a/local/recipes/tui/tlc/source/src/vfs/known_hosts.rs b/local/recipes/tui/tlc/source/src/vfs/known_hosts.rs index 63d29bd9d6..5953618a8f 100644 --- a/local/recipes/tui/tlc/source/src/vfs/known_hosts.rs +++ b/local/recipes/tui/tlc/source/src/vfs/known_hosts.rs @@ -232,7 +232,7 @@ pub fn entry_from_tofu(host: &str, key_type: &str, fingerprint: &str) -> KnownHo hosts: vec![host.to_string()], key_type: key_type.to_string(), fingerprint: fingerprint.to_string(), - comment: Some(format!("first-seen-by-tlc")), + comment: Some("first-seen-by-tlc".to_string()), } } diff --git a/local/recipes/tui/tlc/source/src/viewer/mod.rs b/local/recipes/tui/tlc/source/src/viewer/mod.rs index 5706511bb6..4d29e906e1 100644 --- a/local/recipes/tui/tlc/source/src/viewer/mod.rs +++ b/local/recipes/tui/tlc/source/src/viewer/mod.rs @@ -517,7 +517,7 @@ impl Viewer { fn footer_text(&self) -> String { let pct = if self.goto.line_count() > 0 { - let p = (self.current_line() as u64 + 1) * 100 / self.goto.line_count() as u64; + let p = (self.current_line() + 1) * 100 / self.goto.line_count(); format!(" {}%", p.min(100)) } else { String::new() diff --git a/local/recipes/tui/tlc/source/src/viewer/source.rs b/local/recipes/tui/tlc/source/src/viewer/source.rs index 00e129b709..bad0d8995a 100644 --- a/local/recipes/tui/tlc/source/src/viewer/source.rs +++ b/local/recipes/tui/tlc/source/src/viewer/source.rs @@ -332,8 +332,7 @@ impl FileSource { let bytes = match self { Self::Inline { bytes } | Self::Compressed { bytes, .. } => bytes.as_slice(), Self::Chunked { .. } => { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + return Err(std::io::Error::other( "save_to requires Inline or Compressed source", )); } diff --git a/local/recipes/tui/tlc/source/src/widget/button.rs b/local/recipes/tui/tlc/source/src/widget/button.rs index 46426c1d60..14e8b394d9 100644 --- a/local/recipes/tui/tlc/source/src/widget/button.rs +++ b/local/recipes/tui/tlc/source/src/widget/button.rs @@ -120,8 +120,8 @@ pub fn render_button_row( if specs.is_empty() || area.width == 0 || area.height == 0 { return; } - let mut widths: Vec = specs.iter().map(|s| button_width(*s)).collect(); - let total: u16 = widths.iter().sum::() + (specs.len() as u16 - 1).max(0) * 2; + let widths: Vec = specs.iter().map(|s| button_width(*s)).collect(); + let total: u16 = widths.iter().sum::() + (specs.len() as u16 - 1) * 2; let mut x = if total < area.width { area.x + (area.width - total) / 2 } else { @@ -165,6 +165,7 @@ fn push_label_spans( .position(|c| c.eq_ignore_ascii_case(&h)) .map(|i| chars[i]) }); + #[allow(clippy::manual_option_zip)] if let Some((hot_idx, hot_char)) = hotkey_char.and_then(|hc| chars.iter().position(|c| *c == hc).map(|i| (i, hc))) { diff --git a/local/recipes/tui/tlc/source/src/widget/dialog.rs b/local/recipes/tui/tlc/source/src/widget/dialog.rs index 9d7e308a51..514a739579 100644 --- a/local/recipes/tui/tlc/source/src/widget/dialog.rs +++ b/local/recipes/tui/tlc/source/src/widget/dialog.rs @@ -8,7 +8,6 @@ use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect}; use ratatui::style::{Color, Style}; -use ratatui::text::Line; use ratatui::widgets::{Paragraph, Wrap}; use ratatui::Frame;