diff options
Diffstat (limited to 'alacritty/src/config')
-rw-r--r-- | alacritty/src/config/bell.rs | 70 | ||||
-rw-r--r-- | alacritty/src/config/color.rs | 212 | ||||
-rw-r--r-- | alacritty/src/config/mod.rs | 14 | ||||
-rw-r--r-- | alacritty/src/config/ui_config.rs | 14 |
4 files changed, 304 insertions, 6 deletions
diff --git a/alacritty/src/config/bell.rs b/alacritty/src/config/bell.rs new file mode 100644 index 00000000..2516e2b3 --- /dev/null +++ b/alacritty/src/config/bell.rs @@ -0,0 +1,70 @@ +use std::time::Duration; + +use alacritty_config_derive::ConfigDeserialize; + +use alacritty_terminal::config::Program; +use alacritty_terminal::term::color::Rgb; + +#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)] +pub struct BellConfig { + /// Visual bell animation function. + pub animation: BellAnimation, + + /// Command to run on bell. + pub command: Option<Program>, + + /// Visual bell flash color. + pub color: Rgb, + + /// Visual bell duration in milliseconds. + duration: u16, +} + +impl Default for BellConfig { + fn default() -> Self { + Self { + color: Rgb { r: 255, g: 255, b: 255 }, + animation: Default::default(), + command: Default::default(), + duration: Default::default(), + } + } +} + +impl BellConfig { + pub fn duration(&self) -> Duration { + Duration::from_millis(self.duration as u64) + } +} + +/// `VisualBellAnimations` are modeled after a subset of CSS transitions and Robert +/// Penner's Easing Functions. +#[derive(ConfigDeserialize, Clone, Copy, Debug, PartialEq, Eq)] +pub enum BellAnimation { + // CSS animation. + Ease, + // CSS animation. + EaseOut, + // Penner animation. + EaseOutSine, + // Penner animation. + EaseOutQuad, + // Penner animation. + EaseOutCubic, + // Penner animation. + EaseOutQuart, + // Penner animation. + EaseOutQuint, + // Penner animation. + EaseOutExpo, + // Penner animation. + EaseOutCirc, + // Penner animation. + Linear, +} + +impl Default for BellAnimation { + fn default() -> Self { + BellAnimation::EaseOutExpo + } +} diff --git a/alacritty/src/config/color.rs b/alacritty/src/config/color.rs new file mode 100644 index 00000000..cd5d964d --- /dev/null +++ b/alacritty/src/config/color.rs @@ -0,0 +1,212 @@ +use serde::de::Error as SerdeError; +use serde::{Deserialize, Deserializer}; + +use alacritty_config_derive::ConfigDeserialize; +use alacritty_terminal::term::color::{CellRgb, Rgb}; + +#[derive(ConfigDeserialize, Clone, Debug, Default, PartialEq, Eq)] +pub struct Colors { + pub primary: PrimaryColors, + pub cursor: InvertedCellColors, + pub vi_mode_cursor: InvertedCellColors, + pub selection: InvertedCellColors, + pub normal: NormalColors, + pub bright: BrightColors, + pub dim: Option<DimColors>, + pub indexed_colors: Vec<IndexedColor>, + pub search: SearchColors, + pub line_indicator: LineIndicatorColors, +} + +impl Colors { + 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(ConfigDeserialize, Copy, Clone, Default, Debug, PartialEq, Eq)] +pub struct LineIndicatorColors { + pub foreground: Option<Rgb>, + pub background: Option<Rgb>, +} + +#[derive(Deserialize, Copy, Clone, Default, Debug, PartialEq, Eq)] +pub struct IndexedColor { + pub color: Rgb, + + index: ColorIndex, +} + +impl IndexedColor { + #[inline] + pub fn index(&self) -> u8 { + self.index.0 + } +} + +#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)] +struct ColorIndex(u8); + +impl<'de> Deserialize<'de> for ColorIndex { + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> + where + D: Deserializer<'de>, + { + let index = u8::deserialize(deserializer)?; + + if index < 16 { + Err(SerdeError::custom( + "Config error: indexed_color's index is {}, but a value bigger than 15 was \ + expected; ignoring setting", + )) + } else { + Ok(Self(index)) + } + } +} + +#[derive(ConfigDeserialize, Debug, Copy, Clone, PartialEq, Eq)] +pub struct InvertedCellColors { + #[config(alias = "text")] + pub foreground: CellRgb, + #[config(alias = "cursor")] + pub background: CellRgb, +} + +impl Default for InvertedCellColors { + fn default() -> Self { + Self { foreground: CellRgb::CellBackground, background: CellRgb::CellForeground } + } +} + +#[derive(ConfigDeserialize, Debug, Copy, Clone, Default, PartialEq, Eq)] +pub struct SearchColors { + pub focused_match: InvertedCellColors, + pub matches: MatchColors, + bar: BarColors, +} + +#[derive(ConfigDeserialize, Debug, Copy, Clone, PartialEq, Eq)] +pub struct MatchColors { + pub foreground: CellRgb, + pub background: CellRgb, +} + +impl Default for MatchColors { + fn default() -> Self { + Self { + background: CellRgb::Rgb(Rgb { r: 0xff, g: 0xff, b: 0xff }), + foreground: CellRgb::Rgb(Rgb { r: 0x00, g: 0x00, b: 0x00 }), + } + } +} + +#[derive(ConfigDeserialize, Debug, Copy, Clone, Default, PartialEq, Eq)] +pub struct BarColors { + foreground: Option<Rgb>, + background: Option<Rgb>, +} + +#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)] +pub struct PrimaryColors { + pub foreground: Rgb, + pub background: Rgb, + pub bright_foreground: Option<Rgb>, + pub dim_foreground: Option<Rgb>, +} + +impl Default for PrimaryColors { + fn default() -> Self { + PrimaryColors { + background: Rgb { r: 0x1d, g: 0x1f, b: 0x21 }, + foreground: Rgb { r: 0xc5, g: 0xc8, b: 0xc6 }, + bright_foreground: Default::default(), + dim_foreground: Default::default(), + } + } +} + +#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)] +pub struct NormalColors { + pub black: Rgb, + pub red: Rgb, + pub green: Rgb, + pub yellow: Rgb, + pub blue: Rgb, + pub magenta: Rgb, + pub cyan: Rgb, + pub white: Rgb, +} + +impl Default for NormalColors { + fn default() -> Self { + NormalColors { + 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 }, + } + } +} + +#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)] +pub struct BrightColors { + pub black: Rgb, + pub red: Rgb, + pub green: Rgb, + pub yellow: Rgb, + pub blue: Rgb, + pub magenta: Rgb, + pub cyan: Rgb, + pub white: Rgb, +} + +impl Default for BrightColors { + fn default() -> Self { + BrightColors { + black: Rgb { r: 0x66, g: 0x66, b: 0x66 }, + red: Rgb { r: 0xd5, g: 0x4e, b: 0x53 }, + green: Rgb { r: 0xb9, g: 0xca, b: 0x4a }, + yellow: Rgb { r: 0xe7, g: 0xc5, b: 0x47 }, + blue: Rgb { r: 0x7a, g: 0xa6, b: 0xda }, + magenta: Rgb { r: 0xc3, g: 0x97, b: 0xd8 }, + cyan: Rgb { r: 0x70, g: 0xc0, b: 0xb1 }, + white: Rgb { r: 0xea, g: 0xea, b: 0xea }, + } + } +} + +#[derive(ConfigDeserialize, Clone, Debug, PartialEq, Eq)] +pub struct DimColors { + pub black: Rgb, + pub red: Rgb, + pub green: Rgb, + pub yellow: Rgb, + pub blue: Rgb, + pub magenta: Rgb, + pub cyan: Rgb, + pub white: Rgb, +} + +impl Default for DimColors { + fn default() -> Self { + DimColors { + black: Rgb { r: 0x13, g: 0x14, b: 0x15 }, + red: Rgb { r: 0x86, g: 0x43, b: 0x43 }, + green: Rgb { r: 0x77, g: 0x7c, b: 0x44 }, + yellow: Rgb { r: 0x9e, g: 0x82, b: 0x4c }, + blue: Rgb { r: 0x55, g: 0x6a, b: 0x7d }, + magenta: Rgb { r: 0x75, g: 0x61, b: 0x7b }, + cyan: Rgb { r: 0x5b, g: 0x7d, b: 0x78 }, + white: Rgb { r: 0x82, g: 0x84, b: 0x82 }, + } + } +} diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs index 0673ffd5..a782f5fe 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -1,5 +1,5 @@ use std::fmt::{self, Display, Formatter}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::{env, fs, io}; use log::{error, info}; @@ -9,6 +9,8 @@ use serde_yaml::Value; use alacritty_terminal::config::{Config as TermConfig, LOG_TARGET_CONFIG}; +pub mod bell; +pub mod color; pub mod debug; pub mod font; pub mod monitor; @@ -123,10 +125,10 @@ pub fn load(options: &Options) -> Config { } /// Attempt to reload the configuration file. -pub fn reload(config_path: &PathBuf, options: &Options) -> Result<Config> { +pub fn reload(config_path: &Path, options: &Options) -> Result<Config> { // Load config, propagating errors. let config_options = options.config_options().clone(); - let mut config = load_from(&config_path, config_options)?; + let mut config = load_from(config_path, config_options)?; // Override config with CLI options. options.override_config(&mut config); @@ -135,7 +137,7 @@ pub fn reload(config_path: &PathBuf, options: &Options) -> Result<Config> { } /// Load configuration file and log errors. -fn load_from(path: &PathBuf, cli_config: Value) -> Result<Config> { +fn load_from(path: &Path, cli_config: Value) -> Result<Config> { match read_config(path, cli_config) { Ok(config) => Ok(config), Err(err) => { @@ -146,7 +148,7 @@ fn load_from(path: &PathBuf, cli_config: Value) -> Result<Config> { } /// Deserialize configuration file from path. -fn read_config(path: &PathBuf, cli_config: Value) -> Result<Config> { +fn read_config(path: &Path, cli_config: Value) -> Result<Config> { let mut config_paths = Vec::new(); let mut config_value = parse_config(&path, &mut config_paths, IMPORT_RECURSION_LIMIT)?; @@ -162,7 +164,7 @@ fn read_config(path: &PathBuf, cli_config: Value) -> Result<Config> { /// Deserialize all configuration files as generic Value. fn parse_config( - path: &PathBuf, + path: &Path, config_paths: &mut Vec<PathBuf>, recursion_limit: usize, ) -> Result<Value> { diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index 25f9fb91..b3b3021a 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -6,7 +6,9 @@ use serde::{Deserialize, Deserializer}; use alacritty_config_derive::ConfigDeserialize; use alacritty_terminal::config::{Percentage, LOG_TARGET_CONFIG}; +use crate::config::bell::BellConfig; use crate::config::bindings::{self, Binding, KeyBinding, MouseBinding}; +use crate::config::color::Colors; use crate::config::debug::Debug; use crate::config::font::Font; use crate::config::mouse::Mouse; @@ -31,6 +33,15 @@ pub struct UIConfig { /// Live config reload. pub live_config_reload: bool, + /// Bell configuration. + pub bell: BellConfig, + + /// RGB values for colors. + pub colors: Colors, + + /// Should draw bold text with brighter colors instead of bold font. + pub draw_bold_text_with_bright_colors: bool, + /// Path where config was loaded from. #[config(skip)] pub config_paths: Vec<PathBuf>, @@ -58,6 +69,9 @@ impl Default for UIConfig { key_bindings: Default::default(), mouse_bindings: Default::default(), background_opacity: Default::default(), + bell: Default::default(), + colors: Default::default(), + draw_bold_text_with_bright_colors: Default::default(), } } } |