From a9d9239fac7cd17257030d66d59cb1259bbf26f2 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sun, 14 Jan 2018 16:57:46 -0800 Subject: [PATCH] Correctly parse colors 232-255 Those are grayscale --- src/theme/color.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/theme/color.rs b/src/theme/color.rs index 7adcadc..873c230 100644 --- a/src/theme/color.rs +++ b/src/theme/color.rs @@ -75,12 +75,19 @@ impl Color { /// /// * Colors 0-7 are base dark colors. /// * Colors 8-15 are base light colors. - /// * Colors 16-255 are rgb colors with 6 values per channel. + /// * Colors 16-231 are rgb colors with 6 values per channel (216 colors). + /// * Colors 232-255 are grayscale colors. pub fn from_256colors(n: u8) -> Self { if n < 8 { Color::Dark(BaseColor::from(n)) } else if n < 16 { Color::Light(BaseColor::from(n)) + } else if n >= 232 { + let n = n - 232; + let value = 8 + 10 * n; + + // TODO: returns a Grayscale value? + Color::Rgb(value, value, value) } else { let n = n - 16; @@ -88,6 +95,10 @@ impl Color { let g = (n % 36) / 6; let b = n % 6; + assert!(r < 5); + assert!(g < 5); + assert!(b < 5); + Color::RgbLowRes(r, g, b) } }