diff options
Diffstat (limited to 'alacritty_terminal')
-rw-r--r-- | alacritty_terminal/src/config/mod.rs | 50 | ||||
-rw-r--r-- | alacritty_terminal/src/config/scrolling.rs | 4 |
2 files changed, 41 insertions, 13 deletions
diff --git a/alacritty_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs index df8d37bd..53aae91a 100644 --- a/alacritty_terminal/src/config/mod.rs +++ b/alacritty_terminal/src/config/mod.rs @@ -40,6 +40,7 @@ use crate::term::color::Rgb; pub const LOG_TARGET_CONFIG: &str = "alacritty_config"; const MAX_SCROLLBACK_LINES: u32 = 100_000; +const DEFAULT_CURSOR_THICKNESS: f32 = 0.15; pub type MockConfig = Config<HashMap<String, serde_yaml::Value>>; @@ -67,7 +68,7 @@ pub struct Config<T> { /// Background opacity from 0.0 to 1.0 #[serde(default, deserialize_with = "failure_default")] - background_opacity: Alpha, + background_opacity: Percentage, /// Window configuration #[serde(default, deserialize_with = "failure_default")] @@ -213,7 +214,7 @@ impl<T> Config<T> { #[inline] pub fn background_opacity(&self) -> f32 { - self.background_opacity.0 + self.background_opacity.0 as f32 } } @@ -242,20 +243,47 @@ impl Default for EscapeChars { } #[serde(default)] -#[derive(Deserialize, Copy, Clone, Debug, Default, PartialEq, Eq)] +#[derive(Deserialize, Copy, Clone, Debug, PartialEq)] pub struct Cursor { #[serde(deserialize_with = "failure_default")] pub style: CursorStyle, #[serde(deserialize_with = "option_explicit_none")] pub vi_mode_style: Option<CursorStyle>, + #[serde(deserialize_with = "deserialize_cursor_thickness")] + thickness: Percentage, #[serde(deserialize_with = "failure_default")] unfocused_hollow: DefaultTrueBool, } impl Cursor { + #[inline] pub fn unfocused_hollow(self) -> bool { self.unfocused_hollow.0 } + + #[inline] + pub fn thickness(self) -> f64 { + self.thickness.0 as f64 + } +} + +impl Default for Cursor { + fn default() -> Self { + Self { + style: Default::default(), + vi_mode_style: Default::default(), + thickness: Percentage::new(DEFAULT_CURSOR_THICKNESS), + unfocused_hollow: Default::default(), + } + } +} + +pub fn deserialize_cursor_thickness<'a, D>(deserializer: D) -> Result<Percentage, D::Error> +where + D: Deserializer<'a>, +{ + Ok(Percentage::deserialize(Value::deserialize(deserializer)?) + .unwrap_or_else(|_| Percentage::new(DEFAULT_CURSOR_THICKNESS))) } #[derive(Clone, Debug, Deserialize, PartialEq, Eq)] @@ -300,13 +328,13 @@ pub struct Delta<T: Default + PartialEq + Eq> { pub y: T, } -/// Wrapper around f32 that represents an alpha value between 0.0 and 1.0 +/// Wrapper around f32 that represents a percentage value between 0.0 and 1.0. #[derive(Clone, Copy, Debug, PartialEq)] -pub struct Alpha(f32); +pub struct Percentage(f32); -impl Alpha { +impl Percentage { pub fn new(value: f32) -> Self { - Alpha(if value < 0.0 { + Percentage(if value < 0.0 { 0.0 } else if value > 1.0 { 1.0 @@ -316,18 +344,18 @@ impl Alpha { } } -impl Default for Alpha { +impl Default for Percentage { fn default() -> Self { - Alpha(1.0) + Percentage(1.0) } } -impl<'a> Deserialize<'a> for Alpha { +impl<'a> Deserialize<'a> for Percentage { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'a>, { - Ok(Alpha::new(f32::deserialize(deserializer)?)) + Ok(Percentage::new(f32::deserialize(deserializer)?)) } } diff --git a/alacritty_terminal/src/config/scrolling.rs b/alacritty_terminal/src/config/scrolling.rs index 358abc3b..899ca1b3 100644 --- a/alacritty_terminal/src/config/scrolling.rs +++ b/alacritty_terminal/src/config/scrolling.rs @@ -45,7 +45,7 @@ struct ScrollingMultiplier(u8); impl Default for ScrollingMultiplier { fn default() -> Self { - ScrollingMultiplier(3) + Self(3) } } @@ -54,7 +54,7 @@ struct ScrollingHistory(u32); impl Default for ScrollingHistory { fn default() -> Self { - ScrollingHistory(10_000) + Self(10_000) } } |