1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-10 15:04:32 +03:00

add audible_bell config option

This allows using the system beep sound, currently only on macos.

refs: #3
This commit is contained in:
Wez Furlong 2021-09-26 12:55:19 -07:00
parent 9be8f92d7c
commit 72cb110b65
8 changed files with 58 additions and 2 deletions

View File

@ -50,3 +50,16 @@ pub struct VisualBell {
pub fade_out_function: EasingFunction,
}
impl_lua_conversion!(VisualBell);
#[derive(Debug, Deserialize, Serialize, Clone)]
pub enum AudibleBell {
SystemBeep,
Disabled,
}
impl_lua_conversion!(AudibleBell);
impl Default for AudibleBell {
fn default() -> AudibleBell {
Self::SystemBeep
}
}

View File

@ -1227,6 +1227,9 @@ pub struct Config {
#[serde(default)]
pub visual_bell: VisualBell,
#[serde(default)]
pub audible_bell: AudibleBell,
}
impl_lua_conversion!(Config);

View File

@ -50,7 +50,7 @@ As features stabilize some brief notes about them will accumulate here.
* Fixed: italic fonts weren't always recognized as being italic, resulting in italic variants being used instead of the non-italic variants in some cases! [#1162](https://github.com/wez/wezterm/issues/1162)
* New: [bell](config/lua/window-events/bell.md) event allows you to trigger lua code when the bell is run. [#3](https://github.com/wez/wezterm/issues/3)
* Fixed: Ask freetype for cell metrics in bitmap-only fonts, rather than simply taking the bitmap width. [#1165](https://github.com/wez/wezterm/issues/1165)
* New: [visual_bell](config/lua/config/visual_bell.md) configuration option
* New: [visual_bell](config/lua/config/visual_bell.md) and [audible_bell](config/lua/config/audible_bell.md) configuration options
* New: [wezterm.action_callback](config/lua/wezterm/action_callback.md) function to make it easier to use custom events. Thanks to [@bew](https://github.com/bew)! [#1151](https://github.com/wez/wezterm/pull/1151)
### 20210814-124438-54e29167

View File

@ -0,0 +1,17 @@
# audible_bell
*Since: nightly builds only*
When the BEL ascii sequence is sent to a pane, the bell is "rung" in that pane.
You may choose to configure the `audible_bell` option to change the sound
that wezterm makes when the bell rings.
The follow are possible values:
* `"SystemBeep"` - perform the system beep or alert sound. This is the default. On some systems, it may not produce a beep sound.
* `"Disabled"` - don't make a sound
See also [visual_bell](visual_bell.md).

View File

@ -42,3 +42,5 @@ return {
},
}
```
See also [audible_bell](audible_bell.md).

View File

@ -22,7 +22,8 @@ use config::keyassignment::{
ClipboardCopyDestination, ClipboardPasteSource, InputMap, KeyAssignment, SpawnCommand,
};
use config::{
configuration, ConfigHandle, GradientOrientation, TermConfig, WindowCloseConfirmation,
configuration, AudibleBell, ConfigHandle, GradientOrientation, TermConfig,
WindowCloseConfirmation,
};
use luahelper::impl_lua_conversion;
use mlua::FromLua;
@ -808,6 +809,13 @@ impl TermWindow {
alert: Alert::Bell,
pane_id,
} => {
match self.config.audible_bell {
AudibleBell::SystemBeep => {
Connection::get().expect("on main thread").beep();
}
AudibleBell::Disabled => {}
}
log::info!("Ding! (this is the bell) in pane {}", pane_id);
self.emit_window_event("bell", Some(pane_id));

View File

@ -45,4 +45,7 @@ pub trait ConnectionOps {
/// This actions hides all of the windows of the application and switches
/// focus away from it.
fn hide_application(&self) {}
/// Perform the system beep/notification sound
fn beep(&self) {}
}

View File

@ -112,4 +112,14 @@ impl ConnectionOps for Connection {
let () = msg_send![self.ns_app, hide: self.ns_app];
}
}
fn beep(&self) {
unsafe {
NSBeep();
}
}
}
extern "C" {
fn NSBeep();
}