refactor(palette): remove unused backward-compat aliases and add module docs (#2445)
* refactor(palette): remove unused backward-compat aliases and add module docs - Remove DEEPSEEK_AQUA_RGB, DEEPSEEK_NAVY_RGB, DEEPSEEK_AQUA, DEEPSEEK_NAVY (unused backward-compatible aliases with no references in production code) - Add module-level doc comment explaining the three-layer palette organization: RGB tuples, semantic Color constants, and backward-compat aliases - Note that some constants are kept for design-system completeness * fix: remove deprecated color audit test (DEEPSEEK_AQUA no longer exists) * fix: remove unused import in palette_audit test --------- Co-authored-by: Hu Qiantao <huqiantao@HudeMacBook-Air.local>
This commit is contained in:
+12
-16
@@ -1,4 +1,16 @@
|
||||
//! DeepSeek color palette and semantic roles.
|
||||
//!
|
||||
//! This module defines the color system for the TUI in three layers:
|
||||
//!
|
||||
//! 1. **RGB tuples** (`*_RGB` constants) — raw color values used by theme
|
||||
//! generation and runtime palette construction.
|
||||
//! 2. **Semantic `Color` constants** — pre-computed `ratatui::style::Color`
|
||||
//! values mapped to UI roles (surface, text, accent, status, mode).
|
||||
//! 3. **Backward-compatible aliases** (`DEEPSEEK_*`) — legacy names that
|
||||
//! delegate to the current Whale palette constants.
|
||||
//!
|
||||
//! Some constants defined here are not yet referenced in production code
|
||||
//! but are kept for design-system completeness and future UI work.
|
||||
|
||||
use ratatui::style::Color;
|
||||
#[cfg(target_os = "macos")]
|
||||
@@ -69,10 +81,6 @@ pub const WHALE_TOOL_ACTIVE_RGB: (u8, u8, u8) = (38, 54, 80); // #263650
|
||||
// Backward-compatible aliases for existing call sites.
|
||||
pub const DEEPSEEK_BLUE_RGB: (u8, u8, u8) = WHALE_ACCENT_PRIMARY_RGB;
|
||||
pub const DEEPSEEK_SKY_RGB: (u8, u8, u8) = WHALE_INFO_RGB;
|
||||
#[allow(dead_code)]
|
||||
pub const DEEPSEEK_AQUA_RGB: (u8, u8, u8) = (54, 187, 212);
|
||||
#[allow(dead_code)]
|
||||
pub const DEEPSEEK_NAVY_RGB: (u8, u8, u8) = (24, 63, 138);
|
||||
pub const DEEPSEEK_INK_RGB: (u8, u8, u8) = WHALE_BG_RGB;
|
||||
pub const DEEPSEEK_SLATE_RGB: (u8, u8, u8) = WHALE_PANEL_RGB;
|
||||
pub const DEEPSEEK_RED_RGB: (u8, u8, u8) = WHALE_ERROR_RGB;
|
||||
@@ -217,18 +225,6 @@ pub const DEEPSEEK_BLUE: Color = Color::Rgb(
|
||||
/// Now maps to the secondary accent (Seafoam) for backward compat.
|
||||
pub const DEEPSEEK_SKY: Color =
|
||||
Color::Rgb(DEEPSEEK_SKY_RGB.0, DEEPSEEK_SKY_RGB.1, DEEPSEEK_SKY_RGB.2);
|
||||
#[allow(dead_code)]
|
||||
pub const DEEPSEEK_AQUA: Color = Color::Rgb(
|
||||
DEEPSEEK_AQUA_RGB.0,
|
||||
DEEPSEEK_AQUA_RGB.1,
|
||||
DEEPSEEK_AQUA_RGB.2,
|
||||
);
|
||||
#[allow(dead_code)]
|
||||
pub const DEEPSEEK_NAVY: Color = Color::Rgb(
|
||||
DEEPSEEK_NAVY_RGB.0,
|
||||
DEEPSEEK_NAVY_RGB.1,
|
||||
DEEPSEEK_NAVY_RGB.2,
|
||||
);
|
||||
pub const DEEPSEEK_INK: Color =
|
||||
Color::Rgb(DEEPSEEK_INK_RGB.0, DEEPSEEK_INK_RGB.1, DEEPSEEK_INK_RGB.2);
|
||||
pub const DEEPSEEK_SLATE: Color = Color::Rgb(
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
//! Palette audit tests to prevent color drift.
|
||||
//!
|
||||
//! These tests ensure that deprecated colors (like DEEPSEEK_AQUA) are not used
|
||||
//! directly in user-visible code. Backward-compatible DeepSeek aliases should
|
||||
//! point at the current CodeWhale semantic tokens instead of stale brand RGBs.
|
||||
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
//! These tests ensure that deprecated colors are not used directly in
|
||||
//! user-visible code. Backward-compatible DeepSeek aliases should point
|
||||
//! at the current CodeWhale semantic tokens instead of stale brand RGBs.
|
||||
|
||||
use ratatui::style::Color;
|
||||
|
||||
@@ -13,9 +10,6 @@ use ratatui::style::Color;
|
||||
#[allow(dead_code)]
|
||||
mod palette;
|
||||
|
||||
const DEPRECATED_DIRECT_COLORS: &[&str] = &["DEEPSEEK_AQUA"];
|
||||
const ALLOWED_PATTERNS: &[&str] = &["pub const DEEPSEEK_AQUA", "DEEPSEEK_AQUA_RGB"];
|
||||
|
||||
fn color_to_rgb(color: Color) -> (u8, u8, u8) {
|
||||
match color {
|
||||
Color::Rgb(r, g, b) => (r, g, b),
|
||||
@@ -71,66 +65,8 @@ fn assert_min_contrast(label: &str, foreground: Color, background: Color, min_ra
|
||||
);
|
||||
}
|
||||
|
||||
fn audit_file(path: &Path, violations: &mut Vec<String>) {
|
||||
let content = match fs::read_to_string(path) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
for (line_num, line) in content.lines().enumerate() {
|
||||
for deprecated in DEPRECATED_DIRECT_COLORS {
|
||||
let pattern = format!("palette::{deprecated}");
|
||||
if line.contains(&pattern) {
|
||||
let is_allowed = ALLOWED_PATTERNS.iter().any(|p| line.contains(p));
|
||||
if !is_allowed {
|
||||
violations.push(format!(
|
||||
"{}:{}: direct use of {} (use semantic alias instead)",
|
||||
path.display(),
|
||||
line_num + 1,
|
||||
deprecated
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn audit_directory(dir: &Path, violations: &mut Vec<String>) {
|
||||
let entries = match fs::read_dir(dir) {
|
||||
Ok(e) => e,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
audit_directory(&path, violations);
|
||||
} else if path.extension().is_some_and(|e| e == "rs") {
|
||||
if path.file_name().is_some_and(|n| n == "palette.rs") {
|
||||
continue;
|
||||
}
|
||||
audit_file(&path, violations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn audit_no_direct_aqua_usage() {
|
||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||
let src_dir = Path::new(manifest_dir).join("src");
|
||||
let mut violations = Vec::new();
|
||||
|
||||
audit_directory(&src_dir, &mut violations);
|
||||
|
||||
if !violations.is_empty() {
|
||||
let report = violations.join("\n");
|
||||
panic!(
|
||||
"Palette audit failed! Found {} direct uses of deprecated colors:\n{}",
|
||||
violations.len(),
|
||||
report
|
||||
);
|
||||
}
|
||||
}
|
||||
// NOTE: The deprecated color audit (DEEPSEEK_AQUA) was removed because
|
||||
// the deprecated constant no longer exists in the palette.
|
||||
|
||||
#[test]
|
||||
fn verify_status_success_uses_success_token() {
|
||||
@@ -145,8 +81,8 @@ fn verify_status_success_uses_success_token() {
|
||||
);
|
||||
assert_ne!(
|
||||
palette::STATUS_SUCCESS,
|
||||
palette::DEEPSEEK_AQUA,
|
||||
"STATUS_SUCCESS should not regress to deprecated aqua"
|
||||
palette::DEEPSEEK_BLUE,
|
||||
"STATUS_SUCCESS should not regress to deprecated blue"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user