mirror of
https://github.com/hanzoai/dev.git
synced 2026-10-25 03:32:32 +00:00
fix(tui/themes): reuse shared ansi color mapping
This commit is contained in:
@@ -136,7 +136,7 @@ pub(crate) fn keyword() -> Color {
|
||||
// Overlay/scrim helper: a dimmed background used behind modal overlays.
|
||||
// We derive it from the current theme background so it looks consistent for
|
||||
// both light and dark themes.
|
||||
fn color_to_rgb(c: Color) -> (u8, u8, u8) {
|
||||
pub(crate) fn color_to_rgb(c: Color) -> (u8, u8, u8) {
|
||||
match c {
|
||||
Color::Rgb(r, g, b) => (r, g, b),
|
||||
Color::Black => (0, 0, 0),
|
||||
|
||||
@@ -9,6 +9,7 @@ use std::path::PathBuf;
|
||||
|
||||
use codex_core::protocol::FileChange;
|
||||
|
||||
use crate::colors::color_to_rgb;
|
||||
use crate::history_cell::PatchEventType;
|
||||
use crate::sanitize::{sanitize_for_tui, Mode as SanitizeMode, Options as SanitizeOptions};
|
||||
|
||||
@@ -633,30 +634,6 @@ fn style_del() -> Style {
|
||||
// --- Very light tinted backgrounds for insert/delete lines ------------------
|
||||
use ratatui::style::Color;
|
||||
|
||||
fn color_to_rgb(c: Color) -> (u8, u8, u8) {
|
||||
match c {
|
||||
Color::Rgb(r, g, b) => (r, g, b),
|
||||
Color::Black => (0, 0, 0),
|
||||
Color::White => (255, 255, 255),
|
||||
Color::Gray => (192, 192, 192),
|
||||
Color::DarkGray => (128, 128, 128),
|
||||
Color::Red => (205, 49, 49),
|
||||
Color::Green => (13, 188, 121),
|
||||
Color::Yellow => (229, 229, 16),
|
||||
Color::Blue => (36, 114, 200),
|
||||
Color::Magenta => (188, 63, 188),
|
||||
Color::Cyan => (17, 168, 205),
|
||||
Color::LightRed => (255, 102, 102),
|
||||
Color::LightGreen => (102, 255, 178),
|
||||
Color::LightYellow => (255, 255, 102),
|
||||
Color::LightBlue => (102, 153, 255),
|
||||
Color::LightMagenta => (255, 102, 255),
|
||||
Color::LightCyan => (102, 255, 255),
|
||||
Color::Indexed(i) => (i, i, i),
|
||||
Color::Reset => color_to_rgb(crate::colors::background()),
|
||||
}
|
||||
}
|
||||
|
||||
fn blend(bg: (u8, u8, u8), fg: (u8, u8, u8), alpha: f32) -> (u8, u8, u8) {
|
||||
let inv = 1.0 - alpha;
|
||||
let r = (bg.0 as f32 * inv + fg.0 as f32 * alpha).round() as u8;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use once_cell::sync::OnceCell;
|
||||
use ratatui::text::{Line, Span};
|
||||
|
||||
use crate::colors::color_to_rgb;
|
||||
|
||||
// syntect imports
|
||||
use syntect::easy::HighlightLines;
|
||||
use syntect::highlighting::{Style as SynStyle, Theme, ThemeItem, ThemeSet, ThemeSettings, StyleModifier, FontStyle, Color as SynColor};
|
||||
@@ -8,32 +10,6 @@ use syntect::parsing::{SyntaxReference, SyntaxSet};
|
||||
use syntect::parsing::SyntaxSetBuilder;
|
||||
use syntect::util::LinesWithEndings;
|
||||
|
||||
// Convert a ratatui Color to RGB tuple; mirrored locally to avoid exposing internals.
|
||||
fn color_to_rgb(c: ratatui::style::Color) -> (u8, u8, u8) {
|
||||
use ratatui::style::Color;
|
||||
match c {
|
||||
Color::Rgb(r, g, b) => (r, g, b),
|
||||
Color::Black => (0, 0, 0),
|
||||
Color::White => (255, 255, 255),
|
||||
Color::Gray => (192, 192, 192),
|
||||
Color::DarkGray => (128, 128, 128),
|
||||
Color::Red => (205, 49, 49),
|
||||
Color::Green => (13, 188, 121),
|
||||
Color::Yellow => (229, 229, 16),
|
||||
Color::Blue => (36, 114, 200),
|
||||
Color::Magenta => (188, 63, 188),
|
||||
Color::Cyan => (17, 168, 205),
|
||||
Color::LightRed => (255, 102, 102),
|
||||
Color::LightGreen => (102, 255, 178),
|
||||
Color::LightYellow => (255, 255, 102),
|
||||
Color::LightBlue => (102, 153, 255),
|
||||
Color::LightMagenta => (255, 102, 255),
|
||||
Color::LightCyan => (102, 255, 255),
|
||||
Color::Indexed(i) => (i, i, i),
|
||||
Color::Reset => (255, 255, 255),
|
||||
}
|
||||
}
|
||||
|
||||
fn relative_luminance(rgb: (u8, u8, u8)) -> f32 {
|
||||
(0.2126 * rgb.0 as f32 + 0.7152 * rgb.1 as f32 + 0.0722 * rgb.2 as f32) / 255.0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user