Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add integrated terminal bell + settings (#53752)

Ian Chamberlain74b15e426bb2
diff --git a/assets/settings/default.json b/assets/settings/default.json
index 098586ee4fc..3bf837abe96 100644
--- a/assets/settings/default.json
+++ b/assets/settings/default.json
@@ -1946,6 +1946,8 @@
"path_hyperlink_timeout_ms": 1,
// Whether to show a badge on the terminal panel icon with the count of open terminals.
"show_count_badge": false,
+ // Whether to invoke the OS-specific alert sound when the terminal bell (BEL character) is printed.
+ "bell": "off",
},
"code_actions_on_format": {},
// Settings related to running tasks.
diff --git a/crates/settings/src/settings_store.rs b/crates/settings/src/settings_store.rs
index bbd1ad0bd97..9215a53760b 100644
--- a/crates/settings/src/settings_store.rs
+++ b/crates/settings/src/settings_store.rs
@@ -2259,6 +2259,105 @@ mod tests {
cx,
);
+ // terminal bell settings - newer accessibility setting
+ check_vscode_import(
+ &mut store,
+ r#"{
+ }
+ "#
+ .unindent(),
+ r#"{ "accessibility.signals.terminalBell": { "sound": "on" } }"#.to_owned(),
+ r#"{
+ "terminal": {
+ "bell": "system"
+ },
+ "base_keymap": "VSCode"
+ }
+ "#
+ .unindent(),
+ cx,
+ );
+
+ // terminal bell settings - newer accessibility setting disabled
+ check_vscode_import(
+ &mut store,
+ r#"{
+ }
+ "#
+ .unindent(),
+ r#"{ "accessibility.signals.terminalBell": { "sound": "off" } }"#.to_owned(),
+ r#"{
+ "terminal": {
+ "bell": "off"
+ },
+ "base_keymap": "VSCode"
+ }
+ "#
+ .unindent(),
+ cx,
+ );
+
+ // terminal bell settings - older enableBell setting (true)
+ check_vscode_import(
+ &mut store,
+ r#"{
+ }
+ "#
+ .unindent(),
+ r#"{ "terminal.integrated.enableBell": true }"#.to_owned(),
+ r#"{
+ "terminal": {
+ "bell": "system"
+ },
+ "base_keymap": "VSCode"
+ }
+ "#
+ .unindent(),
+ cx,
+ );
+
+ // terminal bell settings - older enableBell setting (false)
+ check_vscode_import(
+ &mut store,
+ r#"{
+ }
+ "#
+ .unindent(),
+ r#"{ "terminal.integrated.enableBell": false }"#.to_owned(),
+ r#"{
+ "terminal": {
+ "bell": "off"
+ },
+ "base_keymap": "VSCode"
+ }
+ "#
+ .unindent(),
+ cx,
+ );
+
+ // newer accessibility setting takes precedence over older enableBell
+ check_vscode_import(
+ &mut store,
+ r#"{
+ }
+ "#
+ .unindent(),
+ r#"{
+ "accessibility.signals.terminalBell": { "sound": "off" },
+ "terminal.integrated.enableBell": true
+ }"#
+ .to_owned(),
+ r#"{
+ "terminal": {
+ "bell": "off"
+ },
+ "base_keymap": "VSCode"
+ }
+ "#
+ .unindent(),
+ cx,
+ );
+
// hover sticky settings
check_vscode_import(
&mut store,
diff --git a/crates/settings/src/vscode_import.rs b/crates/settings/src/vscode_import.rs
index 11b1de456dc..a0982b88fdc 100644
--- a/crates/settings/src/vscode_import.rs
+++ b/crates/settings/src/vscode_import.rs
@@ -898,6 +898,21 @@ impl VsCodeSettings {
.read_f32("terminal.integrated.lineHeight")
.map(|lh| TerminalLineHeight::Custom(lh)),
max_scroll_history_lines: self.read_usize("terminal.integrated.scrollback"),
+ bell: self
+ .read_value("accessibility.signals.terminalBell")
+ .and_then(|v| Some(v.get("sound")?.as_str()? == "on"))
+ .or_else(|| {
+ // Older deprecated setting, might as well still support it:
+ self.read_value("terminal.integrated.enableBell")
+ .map(|v| v.as_bool() == Some(true) || v.as_str() == Some("both"))
+ })
+ .map(|enabled| {
+ if enabled {
+ TerminalBell::System
+ } else {
+ TerminalBell::Off
+ }
+ }),
minimum_contrast: None,
option_as_meta: self.read_bool("terminal.integrated.macOptionIsMeta"),
project: self.project_terminal_settings_content(),
diff --git a/crates/settings_content/src/terminal.rs b/crates/settings_content/src/terminal.rs
index 643dea18d10..c7c1013278f 100644
--- a/crates/settings_content/src/terminal.rs
+++ b/crates/settings_content/src/terminal.rs
@@ -179,6 +179,10 @@ pub struct TerminalSettingsContent {
///
/// Default: false
pub show_count_badge: Option<bool>,
+ /// What to do when the `BEL` character (`\a`) is printed to terminal.
+ ///
+ /// Default: "system"
+ pub bell: Option<TerminalBell>,
}
/// Shell configuration to open the terminal with.
@@ -394,6 +398,29 @@ pub struct TerminalToolbarContent {
pub breadcrumbs: Option<bool>,
}
+#[derive(
+ Copy,
+ Clone,
+ Debug,
+ Default,
+ PartialEq,
+ Eq,
+ Serialize,
+ Deserialize,
+ JsonSchema,
+ MergeFrom,
+ strum::VariantArray,
+ strum::VariantNames,
+)]
+#[serde(rename_all = "snake_case")]
+pub enum TerminalBell {
+ /// Play an OS-specific alert sound.
+ #[default]
+ System,
+ /// Do not play any sound.
+ Off,
+}
+
#[derive(
Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom,
)]
diff --git a/crates/settings_ui/src/page_data.rs b/crates/settings_ui/src/page_data.rs
index 8b41e7d4117..d784f8a7126 100644
--- a/crates/settings_ui/src/page_data.rs
+++ b/crates/settings_ui/src/page_data.rs
@@ -6589,7 +6589,7 @@ fn terminal_page() -> SettingsPage {
]
}
- fn behavior_settings_section() -> [SettingsPageItem; 4] {
+ fn behavior_settings_section() -> [SettingsPageItem; 5] {
[
SettingsPageItem::SectionHeader("Behavior Settings"),
SettingsPageItem::SettingItem(SettingItem {
@@ -6650,6 +6650,19 @@ fn terminal_page() -> SettingsPage {
metadata: None,
files: USER,
}),
+ SettingsPageItem::SettingItem(SettingItem {
+ title: "Audible Bell",
+ description: "Whether to play a sound when the BEL character (`\\a`, `0x07`) is printed",
+ field: Box::new(SettingField {
+ json_path: Some("terminal.bell"),
+ pick: |settings_content| settings_content.terminal.as_ref()?.bell.as_ref(),
+ write: |settings_content, value| {
+ settings_content.terminal.get_or_insert_default().bell = value;
+ },
+ }),
+ metadata: None,
+ files: USER,
+ }),
]
}
diff --git a/crates/settings_ui/src/settings_ui.rs b/crates/settings_ui/src/settings_ui.rs
index 7301e03b68d..cfc0906d5b8 100644
--- a/crates/settings_ui/src/settings_ui.rs
+++ b/crates/settings_ui/src/settings_ui.rs
@@ -560,6 +560,7 @@ fn init_renderers(cx: &mut App) {
.add_basic_renderer::<settings::DocumentSymbols>(render_dropdown)
.add_basic_renderer::<settings::AudioInputDeviceName>(render_input_audio_device_dropdown)
.add_basic_renderer::<settings::AudioOutputDeviceName>(render_output_audio_device_dropdown)
+ .add_basic_renderer::<settings::TerminalBell>(render_dropdown)
// please semicolon stay on next line
;
}
diff --git a/crates/terminal/src/terminal_settings.rs b/crates/terminal/src/terminal_settings.rs
index ec784d466b1..86666b06ee1 100644
--- a/crates/terminal/src/terminal_settings.rs
+++ b/crates/terminal/src/terminal_settings.rs
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
pub use settings::AlternateScroll;
use settings::{
- IntoGpui, PathHyperlinkRegex, RegisterSetting, ShowScrollbar, TerminalBlink,
+ IntoGpui, PathHyperlinkRegex, RegisterSetting, ShowScrollbar, TerminalBell, TerminalBlink,
TerminalDockPosition, TerminalLineHeight, VenvSettings, WorkingDirectory,
merge_from::MergeFrom,
};
@@ -52,6 +52,7 @@ pub struct TerminalSettings {
pub path_hyperlink_regexes: Vec<String>,
pub path_hyperlink_timeout_ms: u64,
pub show_count_badge: bool,
+ pub bell: TerminalBell,
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
@@ -133,6 +134,7 @@ impl settings::Settings for TerminalSettings {
.collect(),
path_hyperlink_timeout_ms: project_content.path_hyperlink_timeout_ms.unwrap(),
show_count_badge: user_content.show_count_badge.unwrap(),
+ bell: user_content.bell.unwrap(),
}
}
}
diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs
index 8b38ccdb50f..515b30f50bc 100644
--- a/crates/terminal_view/src/terminal_view.rs
+++ b/crates/terminal_view/src/terminal_view.rs
@@ -20,7 +20,7 @@ use persistence::TerminalDb;
use project::{Project, ProjectEntryId, search::SearchQuery};
use schemars::JsonSchema;
use serde::Deserialize;
-use settings::{Settings, SettingsStore, TerminalBlink, WorkingDirectory};
+use settings::{Settings, SettingsStore, TerminalBell, TerminalBlink, WorkingDirectory};
use std::{
any::Any,
cmp,
@@ -1020,6 +1020,9 @@ fn subscribe_for_terminal_events(
Event::Bell => {
terminal_view.has_bell = true;
+ if let TerminalBell::System = TerminalSettings::get_global(cx).bell {
+ window.play_system_bell();
+ }
cx.emit(Event::Wakeup);
}