2019-10-05 00:29:26 +00:00
|
|
|
use log::error;
|
2019-05-10 11:36:16 +00:00
|
|
|
use serde::{Deserialize, Deserializer};
|
2020-07-09 21:45:22 +00:00
|
|
|
use serde_yaml::Value;
|
2019-05-10 11:36:16 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
use crate::config::{failure_default, LOG_TARGET_CONFIG};
|
2020-07-09 21:45:22 +00:00
|
|
|
use crate::term::color::{CellRgb, Rgb};
|
2019-05-10 11:36:16 +00:00
|
|
|
|
|
|
|
#[serde(default)]
|
2019-10-05 00:29:26 +00:00
|
|
|
#[derive(Deserialize, Clone, Debug, Default, PartialEq, Eq)]
|
2019-05-10 11:36:16 +00:00
|
|
|
pub struct Colors {
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub primary: PrimaryColors,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub cursor: CursorColors,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2020-03-18 02:35:08 +00:00
|
|
|
pub vi_mode_cursor: CursorColors,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2020-11-13 05:40:09 +00:00
|
|
|
pub selection: InvertedCellColors,
|
2019-05-10 11:36:16 +00:00
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
normal: NormalColors,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
bright: BrightColors,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub dim: Option<AnsiColors>,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub indexed_colors: Vec<IndexedColor>,
|
2020-07-09 21:45:22 +00:00
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub search: SearchColors,
|
2019-05-10 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Colors {
|
|
|
|
pub fn normal(&self) -> &AnsiColors {
|
|
|
|
&self.normal.0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bright(&self) -> &AnsiColors {
|
|
|
|
&self.bright.0
|
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
|
|
|
|
pub fn search_bar_foreground(&self) -> Rgb {
|
|
|
|
self.search.bar.foreground.unwrap_or(self.primary.background)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn search_bar_background(&self) -> Rgb {
|
|
|
|
self.search.bar.background.unwrap_or(self.primary.foreground)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
struct DefaultForegroundCellRgb(CellRgb);
|
|
|
|
|
|
|
|
impl Default for DefaultForegroundCellRgb {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self(CellRgb::CellForeground)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Eq)]
|
|
|
|
struct DefaultBackgroundCellRgb(CellRgb);
|
|
|
|
|
|
|
|
impl Default for DefaultBackgroundCellRgb {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self(CellRgb::CellBackground)
|
|
|
|
}
|
2019-05-10 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[serde(default)]
|
2019-10-05 00:29:26 +00:00
|
|
|
#[derive(Deserialize, Clone, Default, Debug, PartialEq, Eq)]
|
2019-05-10 11:36:16 +00:00
|
|
|
pub struct IndexedColor {
|
|
|
|
#[serde(deserialize_with = "deserialize_color_index")]
|
|
|
|
pub index: u8,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub color: Rgb,
|
|
|
|
}
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
fn deserialize_color_index<'a, D>(deserializer: D) -> Result<u8, D::Error>
|
2019-05-10 11:36:16 +00:00
|
|
|
where
|
|
|
|
D: Deserializer<'a>,
|
|
|
|
{
|
2020-07-09 21:45:22 +00:00
|
|
|
let value = Value::deserialize(deserializer)?;
|
2019-05-10 11:36:16 +00:00
|
|
|
match u8::deserialize(value) {
|
|
|
|
Ok(index) => {
|
|
|
|
if index < 16 {
|
|
|
|
error!(
|
2019-10-05 00:29:26 +00:00
|
|
|
target: LOG_TARGET_CONFIG,
|
2019-05-10 11:36:16 +00:00
|
|
|
"Problem with config: indexed_color's index is {}, but a value bigger than 15 \
|
|
|
|
was expected; ignoring setting",
|
|
|
|
index
|
|
|
|
);
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Return value out of range to ignore this color.
|
2019-05-10 11:36:16 +00:00
|
|
|
Ok(0)
|
|
|
|
} else {
|
|
|
|
Ok(index)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(err) => {
|
2019-10-05 00:29:26 +00:00
|
|
|
error!(target: LOG_TARGET_CONFIG, "Problem with config: {}; ignoring setting", err);
|
2019-05-10 11:36:16 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Return value out of range to ignore this color.
|
2019-05-10 11:36:16 +00:00
|
|
|
Ok(0)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
#[derive(Deserialize, Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
|
|
pub struct CursorColors {
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2020-07-09 21:45:22 +00:00
|
|
|
text: DefaultBackgroundCellRgb,
|
2019-05-10 11:36:16 +00:00
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2020-07-09 21:45:22 +00:00
|
|
|
cursor: DefaultForegroundCellRgb,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CursorColors {
|
|
|
|
pub fn text(self) -> CellRgb {
|
|
|
|
self.text.0
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn cursor(self) -> CellRgb {
|
|
|
|
self.cursor.0
|
|
|
|
}
|
2019-05-10 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
#[derive(Deserialize, Debug, Copy, Clone, Default, PartialEq, Eq)]
|
2020-11-13 05:40:09 +00:00
|
|
|
pub struct InvertedCellColors {
|
|
|
|
#[serde(deserialize_with = "failure_default", alias = "text")]
|
|
|
|
foreground: DefaultBackgroundCellRgb,
|
2020-07-09 21:45:22 +00:00
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
background: DefaultForegroundCellRgb,
|
|
|
|
}
|
|
|
|
|
2020-11-13 05:40:09 +00:00
|
|
|
impl InvertedCellColors {
|
|
|
|
pub fn foreground(self) -> CellRgb {
|
|
|
|
self.foreground.0
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn background(self) -> CellRgb {
|
|
|
|
self.background.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
#[derive(Deserialize, Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
|
|
pub struct SearchColors {
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub matches: MatchColors,
|
2019-05-10 11:36:16 +00:00
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2020-11-13 05:40:09 +00:00
|
|
|
pub focused_match: InvertedCellColors,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2020-07-09 21:45:22 +00:00
|
|
|
bar: BarColors,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
|
|
|
|
pub struct MatchColors {
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub foreground: CellRgb,
|
|
|
|
#[serde(deserialize_with = "deserialize_match_background")]
|
|
|
|
pub background: CellRgb,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MatchColors {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self { foreground: CellRgb::default(), background: default_match_background() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn deserialize_match_background<'a, D>(deserializer: D) -> Result<CellRgb, D::Error>
|
|
|
|
where
|
|
|
|
D: Deserializer<'a>,
|
|
|
|
{
|
|
|
|
let value = Value::deserialize(deserializer)?;
|
|
|
|
Ok(CellRgb::deserialize(value).unwrap_or_else(|_| default_match_background()))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn default_match_background() -> CellRgb {
|
|
|
|
CellRgb::Rgb(Rgb { r: 0xff, g: 0xff, b: 0xff })
|
|
|
|
}
|
|
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
#[derive(Deserialize, Debug, Copy, Clone, Default, PartialEq, Eq)]
|
|
|
|
pub struct BarColors {
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
foreground: Option<Rgb>,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
background: Option<Rgb>,
|
2019-05-10 11:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[serde(default)]
|
2019-10-05 00:29:26 +00:00
|
|
|
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
2019-05-10 11:36:16 +00:00
|
|
|
pub struct PrimaryColors {
|
2020-07-09 21:45:22 +00:00
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2019-05-10 11:36:16 +00:00
|
|
|
pub background: Rgb,
|
2020-07-09 21:45:22 +00:00
|
|
|
#[serde(deserialize_with = "failure_default")]
|
2019-05-10 11:36:16 +00:00
|
|
|
pub foreground: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub bright_foreground: Option<Rgb>,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub dim_foreground: Option<Rgb>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for PrimaryColors {
|
|
|
|
fn default() -> Self {
|
|
|
|
PrimaryColors {
|
2020-07-09 21:45:22 +00:00
|
|
|
background: Rgb { r: 0x1d, g: 0x1f, b: 0x21 },
|
|
|
|
foreground: Rgb { r: 0xc5, g: 0xc8, b: 0xc6 },
|
2019-05-10 11:36:16 +00:00
|
|
|
bright_foreground: Default::default(),
|
|
|
|
dim_foreground: Default::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// The 8-colors sections of config.
|
2019-10-05 00:29:26 +00:00
|
|
|
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
2019-05-10 11:36:16 +00:00
|
|
|
pub struct AnsiColors {
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub black: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub red: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub green: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub yellow: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub blue: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub magenta: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub cyan: Rgb,
|
|
|
|
#[serde(deserialize_with = "failure_default")]
|
|
|
|
pub white: Rgb,
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
2019-05-10 11:36:16 +00:00
|
|
|
struct NormalColors(AnsiColors);
|
|
|
|
|
|
|
|
impl Default for NormalColors {
|
|
|
|
fn default() -> Self {
|
|
|
|
NormalColors(AnsiColors {
|
2020-05-16 22:27:31 +00:00
|
|
|
black: Rgb { r: 0x1d, g: 0x1f, b: 0x21 },
|
|
|
|
red: Rgb { r: 0xcc, g: 0x66, b: 0x66 },
|
|
|
|
green: Rgb { r: 0xb5, g: 0xbd, b: 0x68 },
|
|
|
|
yellow: Rgb { r: 0xf0, g: 0xc6, b: 0x74 },
|
|
|
|
blue: Rgb { r: 0x81, g: 0xa2, b: 0xbe },
|
|
|
|
magenta: Rgb { r: 0xb2, g: 0x94, b: 0xbb },
|
|
|
|
cyan: Rgb { r: 0x8a, g: 0xbe, b: 0xb7 },
|
|
|
|
white: Rgb { r: 0xc5, g: 0xc8, b: 0xc6 },
|
2019-05-10 11:36:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
2019-05-10 11:36:16 +00:00
|
|
|
struct BrightColors(AnsiColors);
|
|
|
|
|
|
|
|
impl Default for BrightColors {
|
|
|
|
fn default() -> Self {
|
|
|
|
BrightColors(AnsiColors {
|
|
|
|
black: Rgb { r: 0x66, g: 0x66, b: 0x66 },
|
2020-05-16 22:27:31 +00:00
|
|
|
red: Rgb { r: 0xd5, g: 0x4e, b: 0x53 },
|
|
|
|
green: Rgb { r: 0xb9, g: 0xca, b: 0x4a },
|
2019-05-10 11:36:16 +00:00
|
|
|
yellow: Rgb { r: 0xe7, g: 0xc5, b: 0x47 },
|
|
|
|
blue: Rgb { r: 0x7a, g: 0xa6, b: 0xda },
|
2020-05-16 22:27:31 +00:00
|
|
|
magenta: Rgb { r: 0xc3, g: 0x97, b: 0xd8 },
|
|
|
|
cyan: Rgb { r: 0x70, g: 0xc0, b: 0xb1 },
|
|
|
|
white: Rgb { r: 0xea, g: 0xea, b: 0xea },
|
2019-05-10 11:36:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|