mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 01:46:31 +00:00
Correctly parse colors 232-255
Those are grayscale
This commit is contained in:
parent
3058816f1a
commit
a9d9239fac
@ -75,12 +75,19 @@ impl Color {
|
|||||||
///
|
///
|
||||||
/// * Colors 0-7 are base dark colors.
|
/// * Colors 0-7 are base dark colors.
|
||||||
/// * Colors 8-15 are base light 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 {
|
pub fn from_256colors(n: u8) -> Self {
|
||||||
if n < 8 {
|
if n < 8 {
|
||||||
Color::Dark(BaseColor::from(n))
|
Color::Dark(BaseColor::from(n))
|
||||||
} else if n < 16 {
|
} else if n < 16 {
|
||||||
Color::Light(BaseColor::from(n))
|
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 {
|
} else {
|
||||||
let n = n - 16;
|
let n = n - 16;
|
||||||
|
|
||||||
@ -88,6 +95,10 @@ impl Color {
|
|||||||
let g = (n % 36) / 6;
|
let g = (n % 36) / 6;
|
||||||
let b = n % 6;
|
let b = n % 6;
|
||||||
|
|
||||||
|
assert!(r < 5);
|
||||||
|
assert!(g < 5);
|
||||||
|
assert!(b < 5);
|
||||||
|
|
||||||
Color::RgbLowRes(r, g, b)
|
Color::RgbLowRes(r, g, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user