summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal/src/config/mod.rs
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-04-15 06:50:34 +0300
committerGitHub <noreply@github.com>2020-04-15 03:50:34 +0000
commit33abfe34a86863958e70a6b5109eab5740a6bc81 (patch)
tree7a35c4e477f87a97694c6d2562131a59ab128e05 /alacritty_terminal/src/config/mod.rs
parentab2db49af5467ec972e297259dd8c23022783347 (diff)
Add config option to set cursor thickness
Fixes #3526.
Diffstat (limited to 'alacritty_terminal/src/config/mod.rs')
-rw-r--r--alacritty_terminal/src/config/mod.rs50
1 files changed, 39 insertions, 11 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)?))
}
}