From 5ca8eb4647fd60d4d5fac3c9390f366ed229aff6 Mon Sep 17 00:00:00 2001 From: Bjorn Blomberg Date: Tue, 14 Jul 2026 19:51:44 +0200 Subject: [PATCH] Apply cargo clippy --fix cleanups Co-Authored-By: Claude Fable 5 --- src/app.rs | 19 +++++++------------ src/client.rs | 2 +- src/kitty_gfx.rs | 2 +- src/log.rs | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/app.rs b/src/app.rs index 18a80c6..72da06e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -231,7 +231,7 @@ impl Selection { if s.is_empty() { result.push(' '); } else { - result.push_str(&s); + result.push_str(s); } } else { result.push(' '); @@ -743,7 +743,7 @@ impl App { } // 4. WM-keybinds – bara när ingen terminal är fokuserad - let terminal_focused = self.focused_id.map_or(false, |id| { + let terminal_focused = self.focused_id.is_some_and(|id| { self.windows.iter().any(|w| w.id == id && matches!(w.content, WindowContent::Terminal { .. })) }); if !terminal_focused { @@ -1125,12 +1125,12 @@ impl App { } // 5. Innehållsyta → fokus + vidarebefordra musklick till terminal - let hit = self.windows.iter().rev().find(|w| w.in_content(col, row)).and_then(|w| { + let hit = self.windows.iter().rev().find(|w| w.in_content(col, row)).map(|w| { let (mode, encoding) = match &w.content { WindowContent::Terminal { alive, .. } if *alive => (w.mouse_mode, w.mouse_encoding), _ => (vt100::MouseProtocolMode::None, vt100::MouseProtocolEncoding::Default), }; - Some((w.id, w.content_rect(), mode, encoding)) + (w.id, w.content_rect(), mode, encoding) }); if let Some((id, content_rect, mode, encoding)) = hit { crate::log::log(&format!(" click step5: window={} mode={:?} enc={:?} col={} row={} content_rect={:?}", id, mode, encoding, col, row, content_rect)); @@ -1458,7 +1458,7 @@ impl App { Ok((pty, rx)) => { let parser = vt100::Parser::new(rows, cols, 0); self.next_id += 1; - let title = shell.split('/').last().unwrap_or(shell).to_string(); + let title = shell.split('/').next_back().unwrap_or(shell).to_string(); self.windows.push(FloatingWindow { id, x, @@ -1909,7 +1909,7 @@ fn key_to_bytes(key: KeyEvent, app_cursor: bool, _app_keypad: bool) -> Option String { const ALPHABET: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let mut out = String::with_capacity((data.len() + 2) / 3 * 4); + let mut out = String::with_capacity(data.len().div_ceil(3) * 4); for chunk in data.chunks(3) { let b0 = chunk[0] as u32; let b1 = if chunk.len() > 1 { chunk[1] as u32 } else { 0 }; @@ -2000,12 +2000,7 @@ fn find_apc_g_start(data: &[u8]) -> Option { if data.len() < 3 { return None; } - for i in 0..data.len() - 2 { - if data[i] == 0x1b && data[i + 1] == b'_' && data[i + 2] == b'G' { - return Some(i); - } - } - None + (0..data.len() - 2).find(|&i| data[i] == 0x1b && data[i + 1] == b'_' && data[i + 2] == b'G') } /// Hitta APC slut (ESC \) efter start. Returnerar end offset (inkl. ESC \). diff --git a/src/client.rs b/src/client.rs index ba432a5..63fe598 100644 --- a/src/client.rs +++ b/src/client.rs @@ -38,7 +38,7 @@ pub fn run(socket_path: &str) -> io::Result<()> { match ipc::read_message::<_, ServerMessage>(&mut reader) { Ok(ServerMessage::HelloOk { .. }) => {} _ => { - return Err(io::Error::new(io::ErrorKind::Other, "Ogiltigt svar från server")) + return Err(io::Error::other("Ogiltigt svar från server")) } } diff --git a/src/kitty_gfx.rs b/src/kitty_gfx.rs index 4346d98..b7926d7 100644 --- a/src/kitty_gfx.rs +++ b/src/kitty_gfx.rs @@ -139,7 +139,7 @@ pub fn show_bg( fn base64_encode(data: &[u8]) -> String { const ALPHABET: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - let mut out = String::with_capacity((data.len() + 2) / 3 * 4); + let mut out = String::with_capacity(data.len().div_ceil(3) * 4); for chunk in data.chunks(3) { let b0 = chunk[0] as u32; let b1 = if chunk.len() > 1 { chunk[1] as u32 } else { 0 }; diff --git a/src/log.rs b/src/log.rs index 81f3b8f..651f097 100644 --- a/src/log.rs +++ b/src/log.rs @@ -21,7 +21,7 @@ pub fn init() { match OpenOptions::new().create(true).append(true).open(&path) { Ok(f) => { *LOG.lock().unwrap() = Some(f); - log(&format!("=== TUI-WM startad ===")); + log(&"=== TUI-WM startad ===".to_string()); } Err(e) => eprintln!("log::init: kunde inte öppna {:?}: {}", path, e), }