Color Schemes (#142)

* WIP: Color Schemes

* Import/export using color_schemes config

* Finish color scheme implementation

* Add color scheme rename
This commit is contained in:
Jeremy Soller 2024-02-22 09:55:46 -07:00 committed by GitHub
parent 01052fae0b
commit 89e1dcb83a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 2630 additions and 861 deletions

View file

@ -2,11 +2,14 @@ use alacritty_terminal::{
term::color::Colors,
vte::ansi::{NamedColor, Rgb},
};
use hex_color::HexColor;
use palette::{encoding::Srgb, rgb::Rgb as PRgb, FromColor, Okhsl};
use std::collections::HashMap;
use std::{collections::HashMap, fs};
use crate::config::{ColorScheme, ColorSchemeAnsi};
// Fill missing dim/bright colors with derived values from normal ones.
#[allow(dead_code)]
struct ColorDerive {
dim_saturation_adjustment: f32,
dim_lightness_adjustment: f32,
@ -14,6 +17,7 @@ struct ColorDerive {
bright_lightness_adjustment: f32,
}
#[allow(dead_code)]
impl ColorDerive {
fn new() -> Self {
Self {
@ -138,311 +142,108 @@ fn auto_colors() -> Colors {
colors
}
fn tango_palette() -> Colors {
let mut colors = auto_colors();
impl From<&ColorScheme> for Colors {
fn from(color_scheme: &ColorScheme) -> Self {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
let encode_rgb = |rgb_opt: Option<HexColor>| -> Option<Rgb> {
let rgb = rgb_opt?;
Some(Rgb {
r: rgb.r,
g: rgb.g,
b: rgb.b,
})
};
// Set normal colors
colors[NamedColor::Black] = encode_rgb(color_scheme.normal.black);
colors[NamedColor::Red] = encode_rgb(color_scheme.normal.red);
colors[NamedColor::Green] = encode_rgb(color_scheme.normal.green);
colors[NamedColor::Yellow] = encode_rgb(color_scheme.normal.yellow);
colors[NamedColor::Blue] = encode_rgb(color_scheme.normal.blue);
colors[NamedColor::Magenta] = encode_rgb(color_scheme.normal.magenta);
colors[NamedColor::Cyan] = encode_rgb(color_scheme.normal.cyan);
colors[NamedColor::White] = encode_rgb(color_scheme.normal.white);
// Set bright colors
colors[NamedColor::BrightBlack] = encode_rgb(color_scheme.bright.black);
colors[NamedColor::BrightRed] = encode_rgb(color_scheme.bright.red);
colors[NamedColor::BrightGreen] = encode_rgb(color_scheme.bright.green);
colors[NamedColor::BrightYellow] = encode_rgb(color_scheme.bright.yellow);
colors[NamedColor::BrightBlue] = encode_rgb(color_scheme.bright.blue);
colors[NamedColor::BrightMagenta] = encode_rgb(color_scheme.bright.magenta);
colors[NamedColor::BrightCyan] = encode_rgb(color_scheme.bright.cyan);
colors[NamedColor::BrightWhite] = encode_rgb(color_scheme.bright.white);
// Set dim colors
colors[NamedColor::DimBlack] = encode_rgb(color_scheme.dim.black);
colors[NamedColor::DimRed] = encode_rgb(color_scheme.dim.red);
colors[NamedColor::DimGreen] = encode_rgb(color_scheme.dim.green);
colors[NamedColor::DimYellow] = encode_rgb(color_scheme.dim.yellow);
colors[NamedColor::DimBlue] = encode_rgb(color_scheme.dim.blue);
colors[NamedColor::DimMagenta] = encode_rgb(color_scheme.dim.magenta);
colors[NamedColor::DimCyan] = encode_rgb(color_scheme.dim.cyan);
colors[NamedColor::DimWhite] = encode_rgb(color_scheme.dim.white);
// Set special colors
colors[NamedColor::Foreground] = encode_rgb(color_scheme.foreground);
colors[NamedColor::Background] = encode_rgb(color_scheme.background);
colors[NamedColor::Cursor] = encode_rgb(color_scheme.cursor);
colors[NamedColor::BrightForeground] = encode_rgb(color_scheme.bright_foreground);
colors[NamedColor::DimForeground] = encode_rgb(color_scheme.dim_foreground);
colors
}
}
impl From<(&str, &Colors)> for ColorScheme {
fn from(tuple: (&str, &Colors)) -> Self {
let (name, colors) = tuple;
let encode_rgb = |rgb_opt: Option<Rgb>| -> Option<HexColor> {
let rgb = rgb_opt?;
Some(HexColor::rgb(rgb.r, rgb.g, rgb.b))
};
Self {
name: name.to_string(),
foreground: encode_rgb(colors[NamedColor::Foreground]),
background: encode_rgb(colors[NamedColor::Background]),
cursor: encode_rgb(colors[NamedColor::Cursor]),
bright_foreground: encode_rgb(colors[NamedColor::BrightForeground]),
dim_foreground: encode_rgb(colors[NamedColor::DimForeground]),
normal: ColorSchemeAnsi {
black: encode_rgb(colors[NamedColor::Black]),
red: encode_rgb(colors[NamedColor::Red]),
green: encode_rgb(colors[NamedColor::Green]),
yellow: encode_rgb(colors[NamedColor::Yellow]),
blue: encode_rgb(colors[NamedColor::Blue]),
magenta: encode_rgb(colors[NamedColor::Magenta]),
cyan: encode_rgb(colors[NamedColor::Cyan]),
white: encode_rgb(colors[NamedColor::White]),
},
bright: ColorSchemeAnsi {
black: encode_rgb(colors[NamedColor::BrightBlack]),
red: encode_rgb(colors[NamedColor::BrightRed]),
green: encode_rgb(colors[NamedColor::BrightGreen]),
yellow: encode_rgb(colors[NamedColor::BrightYellow]),
blue: encode_rgb(colors[NamedColor::BrightBlue]),
magenta: encode_rgb(colors[NamedColor::BrightMagenta]),
cyan: encode_rgb(colors[NamedColor::BrightCyan]),
white: encode_rgb(colors[NamedColor::BrightWhite]),
},
dim: ColorSchemeAnsi {
black: encode_rgb(colors[NamedColor::DimBlack]),
red: encode_rgb(colors[NamedColor::DimRed]),
green: encode_rgb(colors[NamedColor::DimGreen]),
yellow: encode_rgb(colors[NamedColor::DimYellow]),
blue: encode_rgb(colors[NamedColor::DimBlue]),
magenta: encode_rgb(colors[NamedColor::DimMagenta]),
cyan: encode_rgb(colors[NamedColor::DimCyan]),
white: encode_rgb(colors[NamedColor::DimWhite]),
},
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x2E3436));
colors[NamedColor::Red] = Some(encode_rgb(0xCC0000));
colors[NamedColor::Green] = Some(encode_rgb(0x4E9A06));
colors[NamedColor::Yellow] = Some(encode_rgb(0xC4A000));
colors[NamedColor::Blue] = Some(encode_rgb(0x3465A4));
colors[NamedColor::Magenta] = Some(encode_rgb(0x75507B));
colors[NamedColor::Cyan] = Some(encode_rgb(0x06989A));
colors[NamedColor::White] = Some(encode_rgb(0xD3D7CF));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x555753));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xEF2929));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x8AE234));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xFCE94F));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x729FCF));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xAD7FA8));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x34E2E2));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xEEEEEC));
colors
}
fn tango_dark() -> Colors {
let mut colors = tango_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::White];
colors[NamedColor::Background] = colors[NamedColor::Black];
colors[NamedColor::BrightForeground] = colors[NamedColor::BrightWhite];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new()
// Dim less so colors are readable with default bg
.with_dim_lightness_adjustment(-0.10)
.fill_missing_dims(&mut colors);
colors
}
fn tango_light() -> Colors {
let mut colors = tango_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::Black];
colors[NamedColor::Background] = colors[NamedColor::BrightWhite];
colors[NamedColor::BrightForeground] = colors[NamedColor::BrightBlack];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
fn linux_console_palette() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x000000));
colors[NamedColor::Red] = Some(encode_rgb(0xAA0000));
colors[NamedColor::Green] = Some(encode_rgb(0x00AA00));
colors[NamedColor::Yellow] = Some(encode_rgb(0xAA5500));
colors[NamedColor::Blue] = Some(encode_rgb(0x0000AA));
colors[NamedColor::Magenta] = Some(encode_rgb(0xAA00AA));
colors[NamedColor::Cyan] = Some(encode_rgb(0x00AAAA));
colors[NamedColor::White] = Some(encode_rgb(0xAAAAAA));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x555555));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xFF5555));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x55FF55));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xFFFF55));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x5555FF));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xFF55FF));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x55FFFF));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xFFFFFF));
colors
}
fn linux_console() -> Colors {
let mut colors = linux_console_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::BrightWhite];
colors[NamedColor::Background] = colors[NamedColor::Black];
colors[NamedColor::BrightForeground] = colors[NamedColor::White];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new()
// Dim less so colors are readable with default bg
.with_dim_lightness_adjustment(-0.10)
.fill_missing_dims(&mut colors);
colors
}
fn xterm_palette() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x000000));
colors[NamedColor::Red] = Some(encode_rgb(0xCD0000));
colors[NamedColor::Green] = Some(encode_rgb(0x00CD00));
colors[NamedColor::Yellow] = Some(encode_rgb(0xCDCD00));
colors[NamedColor::Blue] = Some(encode_rgb(0x0000EE));
colors[NamedColor::Magenta] = Some(encode_rgb(0xCD00CD));
colors[NamedColor::Cyan] = Some(encode_rgb(0x00CDCD));
colors[NamedColor::White] = Some(encode_rgb(0xE5E5E5));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x7F7F7F));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xFF0000));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x00FF00));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xFFFF00));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x5C5CFF));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xFF00FF));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x00FFFF));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xFFFFFF));
colors
}
fn xterm_dark() -> Colors {
let mut colors = xterm_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::BrightWhite];
colors[NamedColor::Background] = colors[NamedColor::Black];
colors[NamedColor::BrightForeground] = colors[NamedColor::White];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new()
// Dim less so colors are readable with default bg
.with_dim_lightness_adjustment(-0.12)
.fill_missing_dims(&mut colors);
colors
}
fn xterm_light() -> Colors {
let mut colors = xterm_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::Black];
colors[NamedColor::Background] = colors[NamedColor::BrightWhite];
colors[NamedColor::BrightForeground] = colors[NamedColor::BrightBlack];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
fn rxvt_palette() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x000000));
colors[NamedColor::Red] = Some(encode_rgb(0xCD0000));
colors[NamedColor::Green] = Some(encode_rgb(0x00CD00));
colors[NamedColor::Yellow] = Some(encode_rgb(0xCDCD00));
colors[NamedColor::Blue] = Some(encode_rgb(0x0000CD));
colors[NamedColor::Magenta] = Some(encode_rgb(0xCD00CD));
colors[NamedColor::Cyan] = Some(encode_rgb(0x00CDCD));
colors[NamedColor::White] = Some(encode_rgb(0xFAEBD7));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x404040));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xFF0000));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x00FF00));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xFFFF00));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x0000FF));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xFF00FF));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x00FFFF));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xFFFFFF));
colors
}
fn rxvt_dark() -> Colors {
let mut colors = rxvt_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::BrightWhite];
colors[NamedColor::Background] = colors[NamedColor::Black];
colors[NamedColor::BrightForeground] = colors[NamedColor::White];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new()
// Dim less so colors are readable with default bg
.with_dim_lightness_adjustment(-0.12)
.fill_missing_dims(&mut colors);
colors
}
fn rxvt_light() -> Colors {
let mut colors = rxvt_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::Black];
colors[NamedColor::Background] = colors[NamedColor::BrightWhite];
colors[NamedColor::BrightForeground] = colors[NamedColor::BrightBlack];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
fn solarized_palette() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x073642));
colors[NamedColor::Red] = Some(encode_rgb(0xDC322F));
colors[NamedColor::Green] = Some(encode_rgb(0x859900));
colors[NamedColor::Yellow] = Some(encode_rgb(0xB58900));
colors[NamedColor::Blue] = Some(encode_rgb(0x268BD2));
colors[NamedColor::Magenta] = Some(encode_rgb(0xD33682));
colors[NamedColor::Cyan] = Some(encode_rgb(0x2AA198));
colors[NamedColor::White] = Some(encode_rgb(0xEEE8D5));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x002B36));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xCB4B16));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x586E75));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0x657B83));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x839496));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0x6C71C4));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x93A1A1));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xFDF6E3));
colors
}
fn solarized_dark() -> Colors {
let mut colors = solarized_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::BrightBlue];
colors[NamedColor::Background] = colors[NamedColor::BrightBlack];
colors[NamedColor::BrightForeground] = colors[NamedColor::Blue];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
fn solarized_light() -> Colors {
let mut colors = solarized_palette();
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::BrightYellow];
colors[NamedColor::Background] = colors[NamedColor::BrightWhite];
colors[NamedColor::BrightForeground] = colors[NamedColor::Yellow];
colors[NamedColor::Cursor] = colors[NamedColor::Foreground];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
}
fn cosmic_dark() -> Colors {
@ -533,308 +334,44 @@ fn cosmic_light() -> Colors {
colors
}
fn gruvbox_dark() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x282828));
colors[NamedColor::Red] = Some(encode_rgb(0xcc241d));
colors[NamedColor::Green] = Some(encode_rgb(0x98971a));
colors[NamedColor::Yellow] = Some(encode_rgb(0xd79921));
colors[NamedColor::Blue] = Some(encode_rgb(0x458588));
colors[NamedColor::Magenta] = Some(encode_rgb(0xb16286));
colors[NamedColor::Cyan] = Some(encode_rgb(0x689d6a));
colors[NamedColor::White] = Some(encode_rgb(0xa89984));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x928374));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xfb4934));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0xb8bb26));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xfabd2f));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x83a598));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xd3869b));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x8ec07c));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xebdbb2));
// Set special colors
colors[NamedColor::Foreground] = colors[NamedColor::BrightWhite];
colors[NamedColor::Background] = colors[NamedColor::Black];
colors[NamedColor::Cursor] = colors[NamedColor::BrightWhite];
colors[NamedColor::BrightForeground] = colors[NamedColor::BrightWhite];
// Fill missing dim colors
ColorDerive::new()
// Dim less so colors are readable with default bg
.with_dim_lightness_adjustment(-0.15)
.fill_missing_dims(&mut colors);
colors
}
fn one_half_dark() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x282c34));
colors[NamedColor::Red] = Some(encode_rgb(0xe06c75));
colors[NamedColor::Green] = Some(encode_rgb(0x98c379));
colors[NamedColor::Yellow] = Some(encode_rgb(0xe5c07b));
colors[NamedColor::Blue] = Some(encode_rgb(0x61afef));
colors[NamedColor::Magenta] = Some(encode_rgb(0xc678dd));
colors[NamedColor::Cyan] = Some(encode_rgb(0x56b6c2));
colors[NamedColor::White] = Some(encode_rgb(0xdcdfe4));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x5d677a));
// Set this before filling bright colors (including BrightForeground)
colors[NamedColor::Foreground] = colors[NamedColor::White];
let color_derive = ColorDerive::new();
// Fill missing bright colors
color_derive.fill_missing_brights(&mut colors);
// Set the rest of special colors
colors[NamedColor::Background] = colors[NamedColor::Black];
colors[NamedColor::Cursor] = colors[NamedColor::BrightWhite];
// Fill missing dim colors
color_derive.fill_missing_dims(&mut colors);
colors
}
fn pop_dark() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |r: u8, g: u8, b: u8| -> Rgb { Rgb { r, g, b } };
// Pop colors (from pop-desktop gsettings)
colors[NamedColor::Black] = Some(encode_rgb(51, 51, 51));
colors[NamedColor::Red] = Some(encode_rgb(204, 0, 0));
colors[NamedColor::Green] = Some(encode_rgb(78, 154, 6));
colors[NamedColor::Yellow] = Some(encode_rgb(196, 160, 0));
colors[NamedColor::Blue] = Some(encode_rgb(52, 101, 164));
colors[NamedColor::Magenta] = Some(encode_rgb(117, 80, 123));
colors[NamedColor::Cyan] = Some(encode_rgb(6, 152, 154));
colors[NamedColor::White] = Some(encode_rgb(211, 215, 207));
colors[NamedColor::BrightBlack] = Some(encode_rgb(136, 128, 124));
colors[NamedColor::BrightRed] = Some(encode_rgb(241, 93, 34));
colors[NamedColor::BrightGreen] = Some(encode_rgb(115, 196, 143));
colors[NamedColor::BrightYellow] = Some(encode_rgb(255, 206, 81));
colors[NamedColor::BrightBlue] = Some(encode_rgb(72, 185, 199));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(173, 127, 168));
colors[NamedColor::BrightCyan] = Some(encode_rgb(52, 226, 226));
colors[NamedColor::BrightWhite] = Some(encode_rgb(238, 238, 236));
// Set special colors
// Pop colors (from pop-desktop gsettings)
colors[NamedColor::Foreground] = Some(encode_rgb(242, 242, 242));
colors[NamedColor::Background] = Some(encode_rgb(51, 51, 51));
colors[NamedColor::Cursor] = colors[NamedColor::BrightWhite];
colors[NamedColor::BrightForeground] = colors[NamedColor::BrightWhite];
// Fill missing dim colors
ColorDerive::new()
// Dim less so colors are readable with default bg
.with_dim_lightness_adjustment(-0.05)
.fill_missing_dims(&mut colors);
colors
}
fn selenized_white() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0xEBEBEB));
colors[NamedColor::Red] = Some(encode_rgb(0xD6000C));
colors[NamedColor::Green] = Some(encode_rgb(0x1D9700));
colors[NamedColor::Yellow] = Some(encode_rgb(0xC49700));
colors[NamedColor::Blue] = Some(encode_rgb(0x0064E4));
colors[NamedColor::Magenta] = Some(encode_rgb(0xDD0F9D));
colors[NamedColor::Cyan] = Some(encode_rgb(0x00AD9C));
colors[NamedColor::White] = Some(encode_rgb(0x878787));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0xCDCDCD));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xBF0000));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x008400));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xAF8500));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x0054CF));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xC7008B));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x009A8A));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0x282828));
// Set special colors
colors[NamedColor::Background] = Some(encode_rgb(0xFFFFFF));
colors[NamedColor::Foreground] = Some(encode_rgb(0x474747));
colors[NamedColor::Cursor] = colors[NamedColor::Black];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
fn selenized_light() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0xECE3CC));
colors[NamedColor::Red] = Some(encode_rgb(0xD2212D));
colors[NamedColor::Green] = Some(encode_rgb(0x489100));
colors[NamedColor::Yellow] = Some(encode_rgb(0xAD8900));
colors[NamedColor::Blue] = Some(encode_rgb(0x0072D4));
colors[NamedColor::Magenta] = Some(encode_rgb(0xCA4898));
colors[NamedColor::Cyan] = Some(encode_rgb(0x009C8F));
colors[NamedColor::White] = Some(encode_rgb(0x909995));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0xD5CDB6));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xCC1729));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x428B00));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xA78300));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x006DCE));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xC44392));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x00978A));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0x3A4D53));
// Set special colors
colors[NamedColor::Background] = Some(encode_rgb(0xFBF3DB));
colors[NamedColor::Foreground] = Some(encode_rgb(0x53676D));
colors[NamedColor::Cursor] = colors[NamedColor::Black];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
fn selenized_dark() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x184956));
colors[NamedColor::Red] = Some(encode_rgb(0xFA5750));
colors[NamedColor::Green] = Some(encode_rgb(0x75B938));
colors[NamedColor::Yellow] = Some(encode_rgb(0xDBB32D));
colors[NamedColor::Blue] = Some(encode_rgb(0x4695F7));
colors[NamedColor::Magenta] = Some(encode_rgb(0xF275BE));
colors[NamedColor::Cyan] = Some(encode_rgb(0x41C7B9));
colors[NamedColor::White] = Some(encode_rgb(0x72898F));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x2D5B69));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xFF665C));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x84C747));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xEBC13D));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x58A3FF));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xFF84CD));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x53D6C7));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xCAD8D9));
// Set special colors
colors[NamedColor::Background] = Some(encode_rgb(0x103C48));
colors[NamedColor::Foreground] = Some(encode_rgb(0xADBCBC));
colors[NamedColor::Cursor] = colors[NamedColor::White];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
fn selenized_black() -> Colors {
let mut colors = auto_colors();
let encode_rgb = |data: u32| -> Rgb {
Rgb {
r: (data >> 16) as u8,
g: (data >> 8) as u8,
b: data as u8,
}
};
colors[NamedColor::Black] = Some(encode_rgb(0x252525));
colors[NamedColor::Red] = Some(encode_rgb(0xED4A46));
colors[NamedColor::Green] = Some(encode_rgb(0x70B433));
colors[NamedColor::Yellow] = Some(encode_rgb(0xDBB32D));
colors[NamedColor::Blue] = Some(encode_rgb(0x368AEB));
colors[NamedColor::Magenta] = Some(encode_rgb(0xEB6EB7));
colors[NamedColor::Cyan] = Some(encode_rgb(0x3FC5B7));
colors[NamedColor::White] = Some(encode_rgb(0x777777));
colors[NamedColor::BrightBlack] = Some(encode_rgb(0x3B3B3B));
colors[NamedColor::BrightRed] = Some(encode_rgb(0xFF5E56));
colors[NamedColor::BrightGreen] = Some(encode_rgb(0x83C746));
colors[NamedColor::BrightYellow] = Some(encode_rgb(0xEFC541));
colors[NamedColor::BrightBlue] = Some(encode_rgb(0x4F9CFE));
colors[NamedColor::BrightMagenta] = Some(encode_rgb(0xFF81CA));
colors[NamedColor::BrightCyan] = Some(encode_rgb(0x56D8C9));
colors[NamedColor::BrightWhite] = Some(encode_rgb(0xDEDEDE));
// Set special colors
colors[NamedColor::Background] = Some(encode_rgb(0x181818));
colors[NamedColor::Foreground] = Some(encode_rgb(0xB9B9B9));
colors[NamedColor::Cursor] = colors[NamedColor::White];
// Fill missing dim colors
ColorDerive::new().fill_missing_dims(&mut colors);
colors
}
// Get builtin themes
pub fn terminal_themes() -> HashMap<String, Colors> {
let mut themes = HashMap::new();
themes.insert("Tango Dark".to_string(), tango_dark());
themes.insert("Tango Light".to_string(), tango_light());
themes.insert("XTerm Dark".to_string(), xterm_dark());
themes.insert("XTerm Light".to_string(), xterm_light());
themes.insert("Linux Console".to_string(), linux_console());
themes.insert("Rxvt Dark".to_string(), rxvt_dark());
themes.insert("Rxvt Light".to_string(), rxvt_light());
themes.insert("Solarized Dark".to_string(), solarized_dark());
themes.insert("Solarized Light".to_string(), solarized_light());
themes.insert("COSMIC Dark".to_string(), cosmic_dark());
themes.insert("COSMIC Light".to_string(), cosmic_light());
themes.insert("gruvbox-dark".to_string(), gruvbox_dark());
themes.insert("OneHalfDark".to_string(), one_half_dark());
themes.insert("Pop Dark".to_string(), pop_dark());
themes.insert("Selenized Black".to_string(), selenized_black());
themes.insert("Selenized Dark".to_string(), selenized_dark());
themes.insert("Selenized Light".to_string(), selenized_light());
themes.insert("Selenized White".to_string(), selenized_white());
themes
}
// Helper function to export builtin themes to theme files
#[allow(dead_code)]
pub fn export() {
for (name, theme) in terminal_themes() {
let color_scheme = ColorScheme::from((name.as_str(), &theme));
// Ensure conversion to and from ColorScheme matches original theme
{
let theme_conv = Colors::from(&color_scheme);
for i in 0..alacritty_terminal::term::color::COUNT {
assert_eq!(theme[i], theme_conv[i]);
}
}
let ron = match ron::ser::to_string_pretty(&color_scheme, ron::ser::PrettyConfig::new()) {
Ok(ok) => ok,
Err(err) => {
log::error!("failed to export {name:?}: {err}");
continue;
}
};
let path = format!("color-schemes/{name}.ron");
match fs::write(&path, ron) {
Ok(()) => {
log::info!("exported {path:?}");
}
Err(err) => {
log::error!("failed to esport {path:?}: {err}");
}
}
}
}