Rename {Color,ColorStyle}::Default to TerminalDefault

This commit is contained in:
Alexandre Bury 2017-07-18 01:36:34 +02:00
parent a668e7bc06
commit 2ffae1f524
6 changed files with 61 additions and 51 deletions

View File

@ -8,7 +8,7 @@ use cursive::views::TextView;
fn custom_theme_from_cursive(siv: &Cursive) -> Theme {
let mut theme = siv.current_theme().clone();
theme.colors.background = Color::Default;
theme.colors.background = Color::TerminalDefault;
theme
}

View File

@ -2,7 +2,8 @@ extern crate bear_lib_terminal;
use self::bear_lib_terminal::Color as BltColor;
use self::bear_lib_terminal::geometry::Size;
use self::bear_lib_terminal::terminal::{self, state, Event as BltEvent, KeyCode};
use self::bear_lib_terminal::terminal::{self, state, Event as BltEvent,
KeyCode};
use backend;
use event::{Event, Key};
use std::collections::BTreeMap;
@ -13,16 +14,14 @@ enum ColorRole {
Background,
}
pub struct Concrete {
colours: BTreeMap<i16, (BltColor, BltColor)>,
}
pub struct Concrete {}
impl backend::Backend for Concrete {
fn init() -> Self {
terminal::open("Cursive", 80, 24);
terminal::set(terminal::config::Window::empty().resizeable(true));
Concrete { colours: BTreeMap::new() }
Concrete {}
}
fn finish(&mut self) {
@ -43,9 +42,11 @@ impl backend::Backend for Concrete {
// we'd need the colours in our position,
// but `f()` can do whatever
Effect::Reverse => {
terminal::with_colors(BltColor::from_rgb(0, 0, 0),
terminal::with_colors(
BltColor::from_rgb(0, 0, 0),
BltColor::from_rgb(255, 255, 255),
f)
f,
)
}
}
}
@ -60,7 +61,9 @@ impl backend::Backend for Concrete {
}
fn clear(&self, color: Color) {
terminal::set_background(colour_to_blt_colour(color, ColorRole::Background));
terminal::set_background(
colour_to_blt_colour(color, ColorRole::Background),
);
terminal::clear(None);
}
@ -105,14 +108,14 @@ impl backend::Backend for Concrete {
fn colour_to_blt_colour(clr: Color, role: ColorRole) -> BltColor {
let (r, g, b) = match clr {
Color::Default => {
Color::TerminalDefault => {
let clr = match role {
ColorRole::Foreground => state::foreground(),
ColorRole::Background => state::background(),
};
return clr;
},
}
// Colours taken from
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@ -136,9 +139,11 @@ fn colour_to_blt_colour(clr: Color, role: ColorRole) -> BltColor {
Color::Rgb(r, g, b) => (r, g, b),
Color::RgbLowRes(r, g, b) => {
((r as f32 / 5.0 * 255.0) as u8,
(
(r as f32 / 5.0 * 255.0) as u8,
(g as f32 / 5.0 * 255.0) as u8,
(b as f32 / 5.0 * 255.0) as u8)
(b as f32 / 5.0 * 255.0) as u8,
)
}
};
BltColor::from_rgb(r, g, b)

View File

@ -13,7 +13,7 @@ pub use self::pan::*;
fn find_closest(color: &Color) -> i16 {
match *color {
Color::Default => -1,
Color::TerminalDefault => -1,
Color::Dark(BaseColor::Black) => 0,
Color::Dark(BaseColor::Red) => 1,
Color::Dark(BaseColor::Green) => 2,

View File

@ -197,7 +197,7 @@ fn with_color<F, R>(clr: &theme::Color, f: F) -> R
{
match *clr {
theme::Color::Default => f(&tcolor::Reset),
theme::Color::TerminalDefault => f(&tcolor::Reset),
theme::Color::Dark(theme::BaseColor::Black) => f(&tcolor::Black),
theme::Color::Dark(theme::BaseColor::Red) => f(&tcolor::Red),
theme::Color::Dark(theme::BaseColor::Green) => f(&tcolor::Green),

View File

@ -287,7 +287,6 @@ impl Cursive {
/// Sets the current theme.
pub fn set_theme(&mut self, theme: theme::Theme) {
self.theme = theme;
// self.theme.activate(&mut self.backend);
self.clear();
}

View File

@ -168,7 +168,7 @@ impl ColorPair {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ColorStyle {
/// Style set by terminal before entering a Cursive program.
Default,
TerminalDefault,
/// Application background, where no view is present.
Background,
/// Color used by view shadows. Only background matters.
@ -203,7 +203,10 @@ impl ColorStyle {
pub fn resolve(&self, theme: &Theme) -> ColorPair {
let c = &theme.colors;
let (front, back) = match *self {
ColorStyle::Default => (Color::Default, Color::Default),
ColorStyle::TerminalDefault => (
Color::TerminalDefault,
Color::TerminalDefault,
),
ColorStyle::Background => (c.view, c.background),
ColorStyle::Shadow => (c.shadow, c.shadow),
ColorStyle::Primary => (c.primary, c.view),
@ -331,8 +334,10 @@ impl Palette {
load_color(&mut self.title_primary, table.get("title_primary"));
load_color(&mut self.title_secondary, table.get("title_secondary"));
load_color(&mut self.highlight, table.get("highlight"));
load_color(&mut self.highlight_inactive,
table.get("highlight_inactive"));
load_color(
&mut self.highlight_inactive,
table.get("highlight_inactive"),
);
}
}
@ -415,7 +420,7 @@ impl From<u8> for BaseColor {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Color {
/// Represents a color, preset by terminal.
Default,
TerminalDefault,
/// One of the 8 base colors.
Dark(BaseColor),
/// Lighter version of a base color.
@ -491,6 +496,7 @@ impl Color {
"light magenta" => Color::Light(BaseColor::Magenta),
"light cyan" => Color::Light(BaseColor::Cyan),
"light white" => Color::Light(BaseColor::White),
"default" => Color::TerminalDefault,
value => return Color::parse_special(value),
})
}
@ -514,9 +520,9 @@ impl Color {
let rgb: Vec<_> =
value.chars().map(|c| c as i16 - '0' as i16).collect();
if rgb.iter().all(|&i| i >= 0 && i < 6) {
Some(Color::RgbLowRes(rgb[0] as u8,
rgb[1] as u8,
rgb[2] as u8))
Some(
Color::RgbLowRes(rgb[0] as u8, rgb[1] as u8, rgb[2] as u8),
)
} else {
None
}