summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal/src/config/colors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'alacritty_terminal/src/config/colors.rs')
-rw-r--r--alacritty_terminal/src/config/colors.rs124
1 files changed, 105 insertions, 19 deletions
diff --git a/alacritty_terminal/src/config/colors.rs b/alacritty_terminal/src/config/colors.rs
index ccea9536..13a30bef 100644
--- a/alacritty_terminal/src/config/colors.rs
+++ b/alacritty_terminal/src/config/colors.rs
@@ -1,8 +1,9 @@
use log::error;
use serde::{Deserialize, Deserializer};
+use serde_yaml::Value;
use crate::config::{failure_default, LOG_TARGET_CONFIG};
-use crate::term::color::Rgb;
+use crate::term::color::{CellRgb, Rgb};
#[serde(default)]
#[derive(Deserialize, Clone, Debug, Default, PartialEq, Eq)]
@@ -23,6 +24,8 @@ pub struct Colors {
pub dim: Option<AnsiColors>,
#[serde(deserialize_with = "failure_default")]
pub indexed_colors: Vec<IndexedColor>,
+ #[serde(deserialize_with = "failure_default")]
+ pub search: SearchColors,
}
impl Colors {
@@ -33,6 +36,32 @@ impl Colors {
pub fn bright(&self) -> &AnsiColors {
&self.bright.0
}
+
+ 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)
+ }
}
#[serde(default)]
@@ -44,11 +73,11 @@ pub struct IndexedColor {
pub color: Rgb,
}
-fn deserialize_color_index<'a, D>(deserializer: D) -> ::std::result::Result<u8, D::Error>
+fn deserialize_color_index<'a, D>(deserializer: D) -> Result<u8, D::Error>
where
D: Deserializer<'a>,
{
- let value = serde_yaml::Value::deserialize(deserializer)?;
+ let value = Value::deserialize(deserializer)?;
match u8::deserialize(value) {
Ok(index) => {
if index < 16 {
@@ -78,26 +107,91 @@ where
#[derive(Deserialize, Debug, Copy, Clone, Default, PartialEq, Eq)]
pub struct CursorColors {
#[serde(deserialize_with = "failure_default")]
- pub text: Option<Rgb>,
+ text: DefaultBackgroundCellRgb,
#[serde(deserialize_with = "failure_default")]
- pub cursor: Option<Rgb>,
+ cursor: DefaultForegroundCellRgb,
+}
+
+impl CursorColors {
+ pub fn text(self) -> CellRgb {
+ self.text.0
+ }
+
+ pub fn cursor(self) -> CellRgb {
+ self.cursor.0
+ }
}
#[serde(default)]
#[derive(Deserialize, Debug, Copy, Clone, Default, PartialEq, Eq)]
pub struct SelectionColors {
#[serde(deserialize_with = "failure_default")]
- pub text: Option<Rgb>,
+ text: DefaultBackgroundCellRgb,
+ #[serde(deserialize_with = "failure_default")]
+ background: DefaultForegroundCellRgb,
+}
+
+impl SelectionColors {
+ pub fn text(self) -> CellRgb {
+ self.text.0
+ }
+
+ 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,
#[serde(deserialize_with = "failure_default")]
- pub background: Option<Rgb>,
+ 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>,
}
#[serde(default)]
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct PrimaryColors {
- #[serde(default = "default_background", deserialize_with = "failure_default")]
+ #[serde(deserialize_with = "failure_default")]
pub background: Rgb,
- #[serde(default = "default_foreground", deserialize_with = "failure_default")]
+ #[serde(deserialize_with = "failure_default")]
pub foreground: Rgb,
#[serde(deserialize_with = "failure_default")]
pub bright_foreground: Option<Rgb>,
@@ -108,22 +202,14 @@ pub struct PrimaryColors {
impl Default for PrimaryColors {
fn default() -> Self {
PrimaryColors {
- background: default_background(),
- foreground: default_foreground(),
+ background: Rgb { r: 0x1d, g: 0x1f, b: 0x21 },
+ foreground: Rgb { r: 0xc5, g: 0xc8, b: 0xc6 },
bright_foreground: Default::default(),
dim_foreground: Default::default(),
}
}
}
-fn default_background() -> Rgb {
- Rgb { r: 0x1d, g: 0x1f, b: 0x21 }
-}
-
-fn default_foreground() -> Rgb {
- Rgb { r: 0xc5, g: 0xc8, b: 0xc6 }
-}
-
/// The 8-colors sections of config.
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct AnsiColors {