summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/config
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2020-07-10 22:32:44 +0300
committerGitHub <noreply@github.com>2020-07-10 22:32:44 +0300
commit8bd2c13490f8cb6ad6b0c1104f9586b3554efea2 (patch)
tree6909d3be00c72c3c5acdd173aa7f411a1bc6b445 /alacritty_terminal/src/config
parentb78f3d133960dad38ad21e808723e51661b59881 (diff)
downloadalacritty-8bd2c13490f8cb6ad6b0c1104f9586b3554efea2.tar.gz
alacritty-8bd2c13490f8cb6ad6b0c1104f9586b3554efea2.zip
Add option to run command on bell
Fixes #1528.
Diffstat (limited to 'alacritty_terminal/src/config')
-rw-r--r--alacritty_terminal/src/config/bell.rs120
-rw-r--r--alacritty_terminal/src/config/mod.rs17
-rw-r--r--alacritty_terminal/src/config/visual_bell.rs76
3 files changed, 133 insertions, 80 deletions
diff --git a/alacritty_terminal/src/config/bell.rs b/alacritty_terminal/src/config/bell.rs
new file mode 100644
index 00000000..97010f31
--- /dev/null
+++ b/alacritty_terminal/src/config/bell.rs
@@ -0,0 +1,120 @@
+use std::time::Duration;
+
+use log::error;
+use serde::{Deserialize, Deserializer};
+use serde_yaml::Value;
+
+use crate::config::{failure_default, Program, LOG_TARGET_CONFIG};
+use crate::term::color::Rgb;
+
+const DEFAULT_BELL_COLOR: Rgb = Rgb { r: 255, g: 255, b: 255 };
+
+#[serde(default)]
+#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
+pub struct BellConfig {
+ /// Visual bell animation function.
+ #[serde(deserialize_with = "failure_default")]
+ pub animation: BellAnimation,
+
+ /// Visual bell duration in milliseconds.
+ #[serde(deserialize_with = "failure_default")]
+ duration: u16,
+
+ /// Visual bell flash color.
+ #[serde(deserialize_with = "deserialize_bell_color")]
+ pub color: Rgb,
+
+ /// Command to run on bell.
+ #[serde(deserialize_with = "deserialize_bell_command")]
+ pub command: Option<Program>,
+}
+
+impl Default for BellConfig {
+ fn default() -> Self {
+ Self {
+ animation: Default::default(),
+ duration: Default::default(),
+ command: Default::default(),
+ color: DEFAULT_BELL_COLOR,
+ }
+ }
+}
+
+impl BellConfig {
+ /// Visual bell duration in milliseconds.
+ #[inline]
+ pub fn duration(&self) -> Duration {
+ Duration::from_millis(u64::from(self.duration))
+ }
+}
+
+fn deserialize_bell_color<'a, D>(deserializer: D) -> Result<Rgb, D::Error>
+where
+ D: Deserializer<'a>,
+{
+ let value = Value::deserialize(deserializer)?;
+ match Rgb::deserialize(value) {
+ Ok(value) => Ok(value),
+ Err(err) => {
+ error!(
+ target: LOG_TARGET_CONFIG,
+ "Problem with config: {}, using default color value {}", err, DEFAULT_BELL_COLOR
+ );
+
+ Ok(DEFAULT_BELL_COLOR)
+ },
+ }
+}
+
+fn deserialize_bell_command<'a, D>(deserializer: D) -> Result<Option<Program>, D::Error>
+where
+ D: Deserializer<'a>,
+{
+ // Deserialize to generic value.
+ let val = Value::deserialize(deserializer)?;
+
+ // Accept `None` to disable the bell command.
+ if val.as_str().filter(|v| v.to_lowercase() == "none").is_some() {
+ return Ok(None);
+ }
+
+ match Program::deserialize(val) {
+ Ok(command) => Ok(Some(command)),
+ Err(err) => {
+ error!(target: LOG_TARGET_CONFIG, "Problem with config: {}; ignoring field", err);
+ Ok(None)
+ },
+ }
+}
+
+/// `VisualBellAnimations` are modeled after a subset of CSS transitions and Robert
+/// Penner's Easing Functions.
+#[derive(Clone, Copy, Debug, Deserialize, 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_terminal/src/config/mod.rs b/alacritty_terminal/src/config/mod.rs
index e3d72fda..83dcd7b8 100644
--- a/alacritty_terminal/src/config/mod.rs
+++ b/alacritty_terminal/src/config/mod.rs
@@ -6,20 +6,20 @@ use log::error;
use serde::{Deserialize, Deserializer};
use serde_yaml::Value;
+mod bell;
mod colors;
mod debug;
mod font;
mod scrolling;
-mod visual_bell;
mod window;
use crate::ansi::CursorStyle;
+pub use crate::config::bell::{BellAnimation, BellConfig};
pub use crate::config::colors::Colors;
pub use crate::config::debug::Debug;
pub use crate::config::font::{Font, FontDescription};
pub use crate::config::scrolling::Scrolling;
-pub use crate::config::visual_bell::{VisualBellAnimation, VisualBellConfig};
pub use crate::config::window::{Decorations, Dimensions, StartupMode, WindowConfig, DEFAULT_NAME};
pub const LOG_TARGET_CONFIG: &str = "alacritty_config";
@@ -69,9 +69,9 @@ pub struct Config<T> {
#[serde(default, deserialize_with = "failure_default")]
pub config_path: Option<PathBuf>,
- /// Visual bell configuration.
+ /// Bell configuration.
#[serde(default, deserialize_with = "failure_default")]
- pub visual_bell: VisualBellConfig,
+ bell: BellConfig,
/// Use dynamic title.
#[serde(default, deserialize_with = "failure_default")]
@@ -114,6 +114,10 @@ pub struct Config<T> {
#[serde(skip)]
pub hold: bool,
+ // TODO: DEPRECATED
+ #[serde(default, deserialize_with = "failure_default")]
+ pub visual_bell: Option<BellConfig>,
+
// TODO: REMOVED
#[serde(default, deserialize_with = "failure_default")]
pub tabspaces: Option<usize>,
@@ -176,6 +180,11 @@ impl<T> Config<T> {
pub fn background_opacity(&self) -> f32 {
self.background_opacity.0 as f32
}
+
+ #[inline]
+ pub fn bell(&self) -> &BellConfig {
+ self.visual_bell.as_ref().unwrap_or(&self.bell)
+ }
}
#[serde(default)]
diff --git a/alacritty_terminal/src/config/visual_bell.rs b/alacritty_terminal/src/config/visual_bell.rs
deleted file mode 100644
index 1a0a327b..00000000
--- a/alacritty_terminal/src/config/visual_bell.rs
+++ /dev/null
@@ -1,76 +0,0 @@
-use std::time::Duration;
-
-use serde::Deserialize;
-
-use crate::config::failure_default;
-use crate::term::color::Rgb;
-
-#[serde(default)]
-#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
-pub struct VisualBellConfig {
- /// Visual bell animation function.
- #[serde(deserialize_with = "failure_default")]
- pub animation: VisualBellAnimation,
-
- /// Visual bell duration in milliseconds.
- #[serde(deserialize_with = "failure_default")]
- pub duration: u16,
-
- /// Visual bell flash color.
- #[serde(deserialize_with = "failure_default")]
- pub color: Rgb,
-}
-
-impl Default for VisualBellConfig {
- fn default() -> VisualBellConfig {
- VisualBellConfig {
- animation: Default::default(),
- duration: Default::default(),
- color: default_visual_bell_color(),
- }
- }
-}
-
-impl VisualBellConfig {
- /// Visual bell duration in milliseconds.
- #[inline]
- pub fn duration(&self) -> Duration {
- Duration::from_millis(u64::from(self.duration))
- }
-}
-
-/// `VisualBellAnimations` are modeled after a subset of CSS transitions and Robert
-/// Penner's Easing Functions.
-#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
-pub enum VisualBellAnimation {
- // 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 VisualBellAnimation {
- fn default() -> Self {
- VisualBellAnimation::EaseOutExpo
- }
-}
-
-fn default_visual_bell_color() -> Rgb {
- Rgb { r: 255, g: 255, b: 255 }
-}