diff --git a/Cargo.lock b/Cargo.lock index 5e8a54aeb..e46a19b3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4604,6 +4604,7 @@ dependencies = [ "bitflags 1.2.1", "image", "k9", + "lazy_static", "log", "lru", "num-traits 0.2.14", diff --git a/term/Cargo.toml b/term/Cargo.toml index 965455fef..38708e97c 100644 --- a/term/Cargo.toml +++ b/term/Cargo.toml @@ -17,6 +17,7 @@ use_serde = ["termwiz/use_serde"] anyhow = "1.0" bitflags = "1.0" image = "0.23" +lazy_static = "1.4" log = "0.4" lru = "0.5" num-traits = "0.2" diff --git a/term/src/color.rs b/term/src/color.rs index afafa81ea..7433e2b35 100644 --- a/term/src/color.rs +++ b/term/src/color.rs @@ -94,9 +94,19 @@ impl ColorPalette { } } +lazy_static::lazy_static! { + static ref DEFAULT_PALETTE: ColorPalette = ColorPalette::compute_default(); +} + impl Default for ColorPalette { /// Construct a default color palette fn default() -> ColorPalette { + DEFAULT_PALETTE.clone() + } +} + +impl ColorPalette { + fn compute_default() -> Self { let mut colors = [RgbColor::default(); 256]; // The XTerm ansi color set @@ -201,8 +211,10 @@ impl Default for ColorPalette { colors[0..16].copy_from_slice(&ANSI); - // 216 color cube - static RAMP6: [u8; 6] = [0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF]; + // 216 color cube. + // This isn't the perfect color cube, but it matches the values used + // by xterm, which are slightly brighter. + static RAMP6: [u8; 6] = [0, 0x5f, 0x87, 0xaf, 0xd7, 0xff]; for idx in 0..216 { let blue = RAMP6[idx % 6]; let green = RAMP6[idx / 6 % 6];