mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-24 01:46:31 +00:00
Add grayscale color matching for ncurses backend
This commit is contained in:
parent
800470e22c
commit
fbd4dd97f1
@ -34,11 +34,24 @@ fn find_closest(color: &Color) -> i16 {
|
|||||||
Color::Light(BaseColor::Cyan) => 14,
|
Color::Light(BaseColor::Cyan) => 14,
|
||||||
Color::Light(BaseColor::White) => 15,
|
Color::Light(BaseColor::White) => 15,
|
||||||
Color::Rgb(r, g, b) => {
|
Color::Rgb(r, g, b) => {
|
||||||
|
// If r = g = b, it may be a grayscale value!
|
||||||
|
if r == g && g == b && r != 0 && r < 250 {
|
||||||
|
// (r = g = b) = 8 + 10 * n
|
||||||
|
// (r - 8) / 10 = n
|
||||||
|
//
|
||||||
|
let n = (r - 8) / 10;
|
||||||
|
(232 + n) as i16
|
||||||
|
} else {
|
||||||
let r = 6 * u16::from(r) / 256;
|
let r = 6 * u16::from(r) / 256;
|
||||||
let g = 6 * u16::from(g) / 256;
|
let g = 6 * u16::from(g) / 256;
|
||||||
let b = 6 * u16::from(b) / 256;
|
let b = 6 * u16::from(b) / 256;
|
||||||
(16 + 36 * r + 6 * g + b) as i16
|
(16 + 36 * r + 6 * g + b) as i16
|
||||||
}
|
}
|
||||||
Color::RgbLowRes(r, g, b) => i16::from(16 + 36 * r + 6 * g + b),
|
}
|
||||||
|
Color::RgbLowRes(r, g, b) => {
|
||||||
|
let a = i16::from(16 + 36 * r + 6 * g + b);
|
||||||
|
eprintln!("{:?} => {}", color, a);
|
||||||
|
a
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,6 +213,7 @@ impl backend::Backend for Concrete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn with_color<F: FnOnce()>(&self, colors: ColorPair, f: F) {
|
fn with_color<F: FnOnce()>(&self, colors: ColorPair, f: F) {
|
||||||
|
eprintln!("Color used: {:?}", colors);
|
||||||
let current = self.current_style.get();
|
let current = self.current_style.get();
|
||||||
if current != colors {
|
if current != colors {
|
||||||
self.set_colors(colors);
|
self.set_colors(colors);
|
||||||
|
Loading…
Reference in New Issue
Block a user