diff --git a/src/bin/tcat.rs b/src/bin/tcat.rs index 24c4a68..be1b9d5 100644 --- a/src/bin/tcat.rs +++ b/src/bin/tcat.rs @@ -183,8 +183,8 @@ fn highlight_file(path: &str, ps: &SyntaxSet, ts: &ThemeSet) -> io::Result<()> { let ranges = h.highlight_line(line, ps).unwrap_or_default(); for (style, text) in &ranges { // Strip trailing newline from the last span so reset doesn't leave colour on blank line - let t = if text.ends_with('\n') { - &text[..text.len() - 1] + let t = if let Some(stripped) = text.strip_suffix('\n') { + stripped } else { text }; diff --git a/src/completion.rs b/src/completion.rs index 8207c7a..c248d5c 100644 --- a/src/completion.rs +++ b/src/completion.rs @@ -49,7 +49,7 @@ fn load_history() -> Vec { for line in text.lines().rev() { // Strip extended history prefix: `: 1234567890:0;actual command` let cmd = if line.starts_with(": ") { - match line.splitn(3, ';').nth(1) { + match line.split(';').nth(1) { Some(s) => s, None => line, } diff --git a/src/main.rs b/src/main.rs index 8387c31..cbfef0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -314,12 +314,11 @@ impl App { self.pty_write(b"\x05"); } s => { - if let Some(d) = s.chars().next().and_then(|c| c.to_digit(10)) { - if d >= 1 { + if let Some(d) = s.chars().next().and_then(|c| c.to_digit(10)) + && d >= 1 { self.switch_tab(d as usize - 1); self.sync_window_title(); } - } } }, _ => {} @@ -351,14 +350,13 @@ impl App { } // ── Printable text ──────────────────────────────────────────────────── - if !ctrl && !alt { - if let Some(text) = &event.text { + if !ctrl && !alt + && let Some(text) = &event.text { self.active_mut().ghost_text = None; let bytes = text.as_str().as_bytes().to_vec(); self.active_mut().write(&bytes); return; } - } match &event.logical_key { Key::Named(NamedKey::Enter) => { @@ -600,11 +598,10 @@ impl ApplicationHandler for App { .as_ref() .map(|r| position.y < r.tab_bar_height as f64) .unwrap_or(false); - if in_bar { - if let Some(w) = &self.window { + if in_bar + && let Some(w) = &self.window { w.request_redraw(); } - } } WindowEvent::CursorLeft { .. } => { @@ -620,8 +617,8 @@ impl ApplicationHandler for App { .. } => { let (mx, my) = self.cursor_pos; - if let Some(r) = &self.renderer { - if my >= 0.0 && my < r.tab_bar_height as f64 { + if let Some(r) = &self.renderer + && my >= 0.0 && my < r.tab_bar_height as f64 { let bw = self .window .as_ref() @@ -645,7 +642,6 @@ impl ApplicationHandler for App { w.request_redraw(); } } - } } WindowEvent::MouseWheel { delta, .. } => { diff --git a/src/renderer.rs b/src/renderer.rs index 086ba15..5a9f0bd 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -85,6 +85,7 @@ impl Renderer { } } + #[allow(clippy::too_many_arguments)] // buf+bw+bh are an inherent unit for pixel buffers fn blit( &mut self, buf: &mut [u32], @@ -130,6 +131,7 @@ impl Renderer { } } + #[allow(clippy::too_many_arguments)] fn fill_rect( buf: &mut [u32], bw: usize, @@ -175,6 +177,7 @@ impl Renderer { } /// Filled rounded rectangle with radius `r` pixels (circular corners). + #[allow(clippy::too_many_arguments)] fn fill_rounded( buf: &mut [u32], bw: usize, @@ -360,6 +363,7 @@ impl Renderer { // ── Public render ───────────────────────────────────────────────────────── /// `hover` — hovered tab index, or `tabs.len()` for the + button. + #[allow(clippy::too_many_arguments)] pub fn render( &mut self, buf: &mut [u32], @@ -418,8 +422,8 @@ impl Renderer { } // ── 2. Ghost text ───────────────────────────────────────────────────── - if !state.is_scrolled_back() { - if let Some(g) = ghost { + if !state.is_scrolled_back() + && let Some(g) = ghost { let py = tby + state.cursor_row * ch; for (i, c) in g.chars().enumerate() { let col = state.cursor_col + i; @@ -429,7 +433,6 @@ impl Renderer { self.blit(buf, bw, bh, col * cw, py, c, GHOST_COLOR); } } - } // ── 3. Cursor ───────────────────────────────────────────────────────── if !state.is_scrolled_back() diff --git a/src/terminal.rs b/src/terminal.rs index f910fe0..8a91adc 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -332,7 +332,7 @@ impl Perform for TerminalState { let next = (self.cursor_col / 8 + 1) * 8; self.cursor_col = next.min(self.cols.saturating_sub(1)); } - 0x0a | 0x0b | 0x0c => self.do_newline(), + 0x0a..=0x0c => self.do_newline(), 0x0d => self.cursor_col = 0, _ => {} } @@ -509,11 +509,10 @@ impl Perform for TerminalState { } match params[0] { b"0" | b"2" => { - if params.len() >= 2 { - if let Ok(s) = std::str::from_utf8(params[1]) { + if params.len() >= 2 + && let Ok(s) = std::str::from_utf8(params[1]) { self.title = s.to_string(); } - } } b"7" => { // OSC 7: shell reports current directory as file://hostname/path @@ -524,7 +523,7 @@ impl Perform for TerminalState { .join(";"); let path = content .strip_prefix("file://") - .and_then(|s| s.splitn(2, '/').nth(1)) + .and_then(|s| s.split_once('/').map(|x| x.1)) .map(|s| format!("/{s}")) .unwrap_or(content); if !path.is_empty() {