From 5e7c499d6b91a4c95f78ee352c7b5a24049d3728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20G=C3=BCnzler?= Date: Wed, 10 Apr 2019 23:09:59 +0200 Subject: [PATCH] Add support for running commands on BEL Adds a new configuration option under `visual_bell` called `bell_command` that reuses the command formatting of the keybindings. This allows for things like playing a notification sound. See https://github.com/jwilm/alacritty/issues/1528#issuecomment-425691029 Closes #1072 --- src/config/mod.rs | 10 ++++++++++ src/term/mod.rs | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 14ebc87d79c..b7d8d206139 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -215,6 +215,9 @@ pub struct VisualBellConfig { /// Visual bell flash color #[serde(deserialize_with = "rgb_from_hex")] color: Rgb, + + #[serde(deserialize_with = "failure_default")] + bell_command: Option, } impl Default for VisualBellConfig { @@ -223,6 +226,7 @@ impl Default for VisualBellConfig { animation: Default::default(), duration: Default::default(), color: default_visual_bell_color(), + bell_command: None, } } } @@ -249,6 +253,12 @@ impl VisualBellConfig { pub fn color(&self) -> Rgb { self.color } + + /// Visual bell command + #[inline] + pub fn bell_command(&self) -> Option { + self.bell_command.clone() + } } #[derive(Debug, Deserialize, PartialEq, Eq)] diff --git a/src/term/mod.rs b/src/term/mod.rs index 61bc1509712..a3b4e1464c4 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -25,7 +25,7 @@ use unicode_width::UnicodeWidthChar; use crate::ansi::{ self, Attr, CharsetIndex, Color, CursorStyle, Handler, NamedColor, StandardCharset, }; -use crate::config::{Config, VisualBellAnimation}; +use crate::config::{Config, VisualBellAnimation, CommandWrapper}; use crate::grid::{ BidirectionalIterator, DisplayIter, Grid, GridCell, IndexRegion, Indexed, Scroll, ViewportPosition, @@ -37,6 +37,7 @@ use crate::selection::{self, Locations, Selection}; use crate::term::cell::{Cell, Flags, LineLength}; use crate::term::color::Rgb; use crate::url::{Url, UrlParser}; +use crate::util::start_daemon; use copypasta::{Clipboard, Load, Store}; use font::{self, Size}; @@ -632,6 +633,9 @@ pub struct VisualBell { /// The last time the visual bell rang, if at all start_time: Option, + + /// Command to run when bell is rang + bell_command: Option, } fn cubic_bezier(p0: f64, p1: f64, p2: f64, p3: f64, x: f64) -> f64 { @@ -647,6 +651,7 @@ impl VisualBell { VisualBell { animation: visual_bell_config.animation(), duration: visual_bell_config.duration(), + bell_command: visual_bell_config.bell_command(), start_time: None, } } @@ -737,10 +742,20 @@ impl VisualBell { } } + pub fn run_bell_command(&self) { + if let Some(ref cmd) = self.bell_command { + match start_daemon(cmd.program(), cmd.args()) { + Ok(_) => debug!("Launched {} with args {:?} on bell", cmd.program(), cmd.args()), + Err(_) => warn!("Unable to launch {} with args {:?} on bell", cmd.program(), cmd.args()), + } + } + } + pub fn update_config(&mut self, config: &Config) { let visual_bell_config = config.visual_bell(); self.animation = visual_bell_config.animation(); self.duration = visual_bell_config.duration(); + self.bell_command = visual_bell_config.bell_command(); } } @@ -1708,6 +1723,7 @@ impl ansi::Handler for Term { fn bell(&mut self) { trace!("Bell"); self.visual_bell.ring(); + self.visual_bell.run_bell_command(); self.next_is_urgent = Some(true); }