Skip to content

Commit

Permalink
bell command v2
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgzr committed Jun 29, 2019
1 parent 2329362 commit ff8f9de
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Duration;

use crate::config::bindings::CommandWrapper;
use crate::config::failure_default;
use crate::term::color::Rgb;

Expand Down Expand Up @@ -28,7 +29,7 @@ impl Default for BellConfig {
animation: Default::default(),
duration: Default::default(),
color: default_visual_bell_color(),
bell_command: None,
command: None,
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions alacritty_terminal/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::path::PathBuf;

use serde::{Deserialize, Deserializer};

mod bell;
mod bindings;
mod colors;
mod debug;
Expand All @@ -27,20 +28,19 @@ mod mouse;
mod scrolling;
#[cfg(test)]
mod test;
mod visual_bell;
mod window;

use crate::ansi::CursorStyle;
use crate::input::{Binding, KeyBinding, MouseBinding};

pub use crate::config::bindings::Key;
pub use crate::config::bell::{BellConfig, VisualBellAnimation};
pub use crate::config::bindings::{CommandWrapper, Key};
pub use crate::config::colors::Colors;
pub use crate::config::debug::Debug;
pub use crate::config::font::{Font, FontDescription};
pub use crate::config::monitor::Monitor;
pub use crate::config::mouse::{ClickHandler, Mouse};
pub use crate::config::scrolling::Scrolling;
pub use crate::config::visual_bell::{VisualBellAnimation, VisualBellConfig};
pub use crate::config::window::{Decorations, Dimensions, StartupMode, WindowConfig};

pub static DEFAULT_ALACRITTY_CONFIG: &str =
Expand Down Expand Up @@ -99,9 +99,13 @@ pub struct Config {
#[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,
pub bell: BellConfig,

// TODO: DEPRECATED
#[serde(default, deserialize_with = "failure_default")]
visual_bell: BellConfig,

/// Use dynamic title
#[serde(default, deserialize_with = "failure_default")]
Expand Down
4 changes: 2 additions & 2 deletions alacritty_terminal/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl Display {
pub fn draw(&mut self, terminal: &FairMutex<Term>, config: &Config) {
let mut terminal = terminal.lock();
let size_info = *terminal.size_info();
let visual_bell_intensity = terminal.visual_bell.intensity();
let visual_bell_intensity = terminal.bell.intensity();
let background_color = terminal.background_color();
let metrics = self.glyph_cache.font_metrics();

Expand All @@ -450,7 +450,7 @@ impl Display {
let message_buffer = terminal.message_buffer_mut().message();

// Clear dirty flag
terminal.dirty = !terminal.visual_bell.completed();
terminal.dirty = !terminal.bell.completed();

if let Some(title) = terminal.get_next_title() {
self.window.set_title(&title);
Expand Down
2 changes: 1 addition & 1 deletion alacritty_terminal/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl QuadRenderer {
}

// Draw visual bell
let color = config.visual_bell.color;
let color = config.bell.color;
let rect = Rect::new(0., 0., props.width, props.height);
self.render_rect(&rect, color, visual_bell_intensity as f32, props);

Expand Down
40 changes: 20 additions & 20 deletions alacritty_terminal/src/term/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ pub struct Cursor {
charsets: Charsets,
}

pub struct VisualBell {
pub struct Bell {
/// Visual bell animation
animation: VisualBellAnimation,

Expand All @@ -608,7 +608,7 @@ pub struct VisualBell {
start_time: Option<Instant>,

/// Command to run when bell is rang
bell_command: Option<CommandWrapper>,
command: Option<CommandWrapper>,
}

fn cubic_bezier(p0: f64, p1: f64, p2: f64, p3: f64, x: f64) -> f64 {
Expand All @@ -618,19 +618,20 @@ fn cubic_bezier(p0: f64, p1: f64, p2: f64, p3: f64, x: f64) -> f64 {
+ x.powi(3) * p3
}

impl VisualBell {
pub fn new(config: &Config) -> VisualBell {
let visual_bell_config = &config.visual_bell;
VisualBell {
animation: visual_bell_config.animation,
duration: visual_bell_config.duration(),
bell_command: visual_bell_config.bell_command(),
impl Bell {
pub fn new(config: &Config) -> Bell {
let bell_config = &config.bell;
Bell {
animation: bell_config.animation,
duration: bell_config.duration(),
command: bell_config.command.clone(),
start_time: None,
}
}

/// Ring the visual bell, and return its intensity.
pub fn ring(&mut self) -> f64 {
self.run_command();
let now = Instant::now();
self.start_time = Some(now);
self.intensity_at_instant(now)
Expand Down Expand Up @@ -715,8 +716,8 @@ impl VisualBell {
}
}

pub fn run_bell_command(&self) {
if let Some(ref cmd) = self.bell_command {
pub fn run_command(&self) {
if let Some(ref cmd) = self.command {
match start_daemon(cmd.program(), cmd.args()) {
Ok(_) => debug!("Launched {} with args {:?} on bell", cmd.program(), cmd.args()),
Err(_) => {
Expand All @@ -727,10 +728,10 @@ impl VisualBell {
}

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();
let bell_config = &config.bell;
self.animation = bell_config.animation;
self.duration = bell_config.duration();
self.command = bell_config.command.clone();
}
}

Expand Down Expand Up @@ -784,7 +785,7 @@ pub struct Term {

pub dirty: bool,

pub visual_bell: VisualBell,
pub bell: Bell,
pub next_is_urgent: Option<bool>,

/// Saved cursor from main grid
Expand Down Expand Up @@ -938,7 +939,7 @@ impl Term {
next_title: None,
next_mouse_cursor: None,
dirty: false,
visual_bell: VisualBell::new(config),
bell: Bell::new(config),
next_is_urgent: None,
input_needs_wrap: false,
grid,
Expand Down Expand Up @@ -991,7 +992,7 @@ impl Term {
self.colors[i] = self.original_colors[i];
}
}
self.visual_bell.update_config(config);
self.bell.update_config(config);
self.default_cursor_style = config.cursor.style;
self.dynamic_title = config.dynamic_title();
self.auto_scroll = config.scrolling.auto_scroll;
Expand Down Expand Up @@ -1702,8 +1703,7 @@ impl ansi::Handler for Term {
#[inline]
fn bell(&mut self) {
trace!("Bell");
self.visual_bell.ring();
self.visual_bell.run_bell_command();
self.bell.ring();
self.next_is_urgent = Some(true);
}

Expand Down

0 comments on commit ff8f9de

Please sign in to comment.