style: cargo fmt + clippy fixes for v0.6.6 UI redesign
Run `cargo fmt --all` after the four redesign sub-areas land to settle attribute placement (`#[allow(dead_code)]` lives after doc comments, not between them — interleaving was splitting docs from items). Inline the trailing `let dom = …; dom` in `nearest_ansi16` to satisfy clippy::let_and_return. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+34
-12
@@ -162,11 +162,11 @@ impl ColorDepth {
|
||||
}
|
||||
|
||||
/// Adapt a foreground color to the terminal's color depth.
|
||||
#[allow(dead_code)]
|
||||
///
|
||||
/// On TrueColor, `color` passes through. On Ansi256 we let ratatui's renderer
|
||||
/// down-convert (it does this already). On Ansi16 we strip RGB to a near
|
||||
/// named color so semantic intent survives even on legacy terminals.
|
||||
#[allow(dead_code)]
|
||||
#[must_use]
|
||||
pub fn adapt_color(color: Color, depth: ColorDepth) -> Color {
|
||||
match (color, depth) {
|
||||
@@ -177,9 +177,9 @@ pub fn adapt_color(color: Color, depth: ColorDepth) -> Color {
|
||||
}
|
||||
|
||||
/// Adapt a background color. On Ansi16 terminals background tints are noisy,
|
||||
#[allow(dead_code)]
|
||||
/// so we drop them to `Color::Reset` rather than attempt a coarse named-color
|
||||
/// match — a quiet background reads cleaner than a wrong one.
|
||||
#[allow(dead_code)]
|
||||
#[must_use]
|
||||
pub fn adapt_bg(color: Color, depth: ColorDepth) -> Color {
|
||||
match depth {
|
||||
@@ -239,10 +239,10 @@ pub fn pulse_brightness(color: Color, now_ms: u64) -> Color {
|
||||
}
|
||||
|
||||
/// Map an RGB triple to its closest ANSI-16 named color. Only used by
|
||||
#[allow(dead_code)]
|
||||
/// `adapt_color` on Ansi16 terminals; we lean on hue dominance + lightness so
|
||||
/// brand colors land on the obviously-related named entry (sky → cyan, blue →
|
||||
/// blue, red → red, etc.) rather than dithering around grey.
|
||||
#[allow(dead_code)]
|
||||
fn nearest_ansi16(r: u8, g: u8, b: u8) -> Color {
|
||||
let lum = (u16::from(r) + u16::from(g) + u16::from(b)) / 3;
|
||||
if lum < 24 {
|
||||
@@ -257,11 +257,19 @@ fn nearest_ansi16(r: u8, g: u8, b: u8) -> Color {
|
||||
if max.saturating_sub(min) < 16 {
|
||||
return if bright { Color::Gray } else { Color::DarkGray };
|
||||
}
|
||||
let dom = if r >= g && r >= b {
|
||||
if r >= g && r >= b {
|
||||
if g > b + 24 {
|
||||
if bright { Color::LightYellow } else { Color::Yellow }
|
||||
if bright {
|
||||
Color::LightYellow
|
||||
} else {
|
||||
Color::Yellow
|
||||
}
|
||||
} else if b > r.saturating_sub(24) {
|
||||
if bright { Color::LightMagenta } else { Color::Magenta }
|
||||
if bright {
|
||||
Color::LightMagenta
|
||||
} else {
|
||||
Color::Magenta
|
||||
}
|
||||
} else if bright {
|
||||
Color::LightRed
|
||||
} else {
|
||||
@@ -269,22 +277,33 @@ fn nearest_ansi16(r: u8, g: u8, b: u8) -> Color {
|
||||
}
|
||||
} else if g >= r && g >= b {
|
||||
if b > r + 24 {
|
||||
if bright { Color::LightCyan } else { Color::Cyan }
|
||||
if bright {
|
||||
Color::LightCyan
|
||||
} else {
|
||||
Color::Cyan
|
||||
}
|
||||
} else if bright {
|
||||
Color::LightGreen
|
||||
} else {
|
||||
Color::Green
|
||||
}
|
||||
} else if r > g + 24 {
|
||||
if bright { Color::LightMagenta } else { Color::Magenta }
|
||||
if bright {
|
||||
Color::LightMagenta
|
||||
} else {
|
||||
Color::Magenta
|
||||
}
|
||||
} else if g > r + 24 {
|
||||
if bright { Color::LightCyan } else { Color::Cyan }
|
||||
if bright {
|
||||
Color::LightCyan
|
||||
} else {
|
||||
Color::Cyan
|
||||
}
|
||||
} else if bright {
|
||||
Color::LightBlue
|
||||
} else {
|
||||
Color::Blue
|
||||
};
|
||||
dom
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -316,7 +335,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn adapt_bg_disables_tints_on_ansi16() {
|
||||
assert_eq!(adapt_bg(SURFACE_REASONING, ColorDepth::Ansi16), Color::Reset);
|
||||
assert_eq!(
|
||||
adapt_bg(SURFACE_REASONING, ColorDepth::Ansi16),
|
||||
Color::Reset
|
||||
);
|
||||
assert_eq!(
|
||||
adapt_bg(SURFACE_REASONING, ColorDepth::TrueColor),
|
||||
SURFACE_REASONING
|
||||
|
||||
@@ -1384,10 +1384,7 @@ fn render_thinking(
|
||||
body_style.italic(),
|
||||
));
|
||||
if !low_motion {
|
||||
spans.push(Span::styled(
|
||||
format!(" {REASONING_CURSOR}"),
|
||||
cursor_style,
|
||||
));
|
||||
spans.push(Span::styled(format!(" {REASONING_CURSOR}"), cursor_style));
|
||||
}
|
||||
lines.push(Line::from(spans));
|
||||
}
|
||||
@@ -1399,10 +1396,7 @@ fn render_thinking(
|
||||
// Trailing cursor on the very last body line while streaming —
|
||||
// signals "still generating" without churning every line.
|
||||
if streaming && !low_motion && idx == last_idx {
|
||||
spans.push(Span::styled(
|
||||
format!(" {REASONING_CURSOR}"),
|
||||
cursor_style,
|
||||
));
|
||||
spans.push(Span::styled(format!(" {REASONING_CURSOR}"), cursor_style));
|
||||
}
|
||||
lines.push(Line::from(spans));
|
||||
}
|
||||
@@ -1934,8 +1928,8 @@ mod tests {
|
||||
assistant_label_style_for, extract_reasoning_summary, render_thinking,
|
||||
running_status_label_with_elapsed,
|
||||
};
|
||||
use crate::palette;
|
||||
use crate::deepseek_theme::Theme;
|
||||
use crate::palette;
|
||||
use ratatui::style::Modifier;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -2092,9 +2086,7 @@ mod tests {
|
||||
use ratatui::style::Color;
|
||||
let mut saw_dimmed = false;
|
||||
for _ in 0..50 {
|
||||
if let Some(Color::Rgb(_, _, b)) =
|
||||
assistant_label_style_for(true, false).fg
|
||||
{
|
||||
if let Some(Color::Rgb(_, _, b)) = assistant_label_style_for(true, false).fg {
|
||||
let Color::Rgb(_, _, src_b) = palette::DEEPSEEK_SKY else {
|
||||
panic!("DEEPSEEK_SKY must be RGB");
|
||||
};
|
||||
|
||||
@@ -395,10 +395,7 @@ impl FooterWidget {
|
||||
}
|
||||
|
||||
fn spans_text(spans: &[Span<'_>]) -> String {
|
||||
spans
|
||||
.iter()
|
||||
.map(|s| s.content.as_ref())
|
||||
.collect::<String>()
|
||||
spans.iter().map(|s| s.content.as_ref()).collect::<String>()
|
||||
}
|
||||
|
||||
impl Renderable for FooterWidget {
|
||||
@@ -909,10 +906,7 @@ mod tests {
|
||||
let status_pos = line.find("working").expect("status visible");
|
||||
assert!(mode_pos < model_pos);
|
||||
assert!(model_pos < cost_pos, "cost must follow model: {line:?}");
|
||||
assert!(
|
||||
cost_pos < status_pos,
|
||||
"cost must precede status: {line:?}"
|
||||
);
|
||||
assert!(cost_pos < status_pos, "cost must precede status: {line:?}");
|
||||
}
|
||||
|
||||
/// Cost is preserved when status drops — cost is steady info, status is
|
||||
@@ -925,7 +919,10 @@ mod tests {
|
||||
let line = render_at_width(props, 47);
|
||||
assert!(line.contains("agent"));
|
||||
assert!(line.contains("deepseek-v4-flash"));
|
||||
assert!(line.contains("$0.42"), "cost survives status drop: {line:?}");
|
||||
assert!(
|
||||
line.contains("$0.42"),
|
||||
"cost survives status drop: {line:?}"
|
||||
);
|
||||
assert!(!line.contains("refreshing"), "status dropped: {line:?}");
|
||||
}
|
||||
|
||||
|
||||
@@ -88,14 +88,14 @@ pub fn tool_family_for_name(name: &str) -> ToolFamily {
|
||||
#[must_use]
|
||||
pub fn family_glyph(family: ToolFamily) -> &'static str {
|
||||
match family {
|
||||
ToolFamily::Read => "\u{25B7}", // ▷
|
||||
ToolFamily::Patch => "\u{25C6}", // ◆
|
||||
ToolFamily::Run => "\u{25B6}", // ▶
|
||||
ToolFamily::Find => "\u{2315}", // ⌕
|
||||
ToolFamily::Delegate => "\u{25D0}", // ◐
|
||||
ToolFamily::Read => "\u{25B7}", // ▷
|
||||
ToolFamily::Patch => "\u{25C6}", // ◆
|
||||
ToolFamily::Run => "\u{25B6}", // ▶
|
||||
ToolFamily::Find => "\u{2315}", // ⌕
|
||||
ToolFamily::Delegate => "\u{25D0}", // ◐
|
||||
ToolFamily::Fanout => "\u{22EE}\u{22EE}", // ⋮⋮ (two cells)
|
||||
ToolFamily::Think => "\u{2026}", // …
|
||||
ToolFamily::Generic => "\u{2022}", // •
|
||||
ToolFamily::Think => "\u{2026}", // …
|
||||
ToolFamily::Generic => "\u{2022}", // •
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,10 @@ mod tests {
|
||||
assert_eq!(tool_family_for_name("agent_spawn"), ToolFamily::Delegate);
|
||||
assert_eq!(tool_family_for_name("agent_swarm"), ToolFamily::Fanout);
|
||||
assert_eq!(tool_family_for_name("rlm"), ToolFamily::Fanout);
|
||||
assert_eq!(tool_family_for_name("totally_new_tool"), ToolFamily::Generic);
|
||||
assert_eq!(
|
||||
tool_family_for_name("totally_new_tool"),
|
||||
ToolFamily::Generic
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user