diff --git a/assets/settings/default.json b/assets/settings/default.json index f3ddba1e42..b12bd00efa 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -197,7 +197,20 @@ // enviroment. Use `:` to seperate multiple values. "env": { // "KEY": "value1:value2" - } + }, + // Set the terminal's line height. + // May take 3 values: + // 1. Use a line height that's comfortable for reading, 1.618 + // "line_height": "comfortable" + // 2. Use a standard line height, 1.3. This option is useful for TUIs, + // particularly if they use box characters + // "line_height": "standard", + // 3. Use a custom line height. + // "line_height": { + // "custom": 2 + // }, + // + "line_height": "comfortable" // Set the terminal's font size. If this option is not included, // the terminal will default to matching the buffer's font size. // "font_size": "15" diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index 6942a6e57b..f2082be6bb 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -252,6 +252,7 @@ pub struct TerminalSettings { pub working_directory: Option, pub font_size: Option, pub font_family: Option, + pub line_height: Option, pub font_features: Option, pub env: Option>, pub blinking: Option, @@ -260,6 +261,25 @@ pub struct TerminalSettings { pub copy_on_select: Option, } +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, Default)] +#[serde(rename_all = "snake_case")] +pub enum TerminalLineHeight { + #[default] + Comfortable, + Standard, + Custom(f32), +} + +impl TerminalLineHeight { + fn value(&self) -> f32 { + match self { + TerminalLineHeight::Comfortable => 1.618, + TerminalLineHeight::Standard => 1.3, + TerminalLineHeight::Custom(line_height) => *line_height, + } + } +} + #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum TerminalBlink { @@ -316,6 +336,14 @@ impl Default for WorkingDirectory { } } +impl TerminalSettings { + fn line_height(&self) -> Option { + self.line_height + .to_owned() + .map(|line_height| line_height.value()) + } +} + #[derive(PartialEq, Eq, Debug, Default, Copy, Clone, Hash, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum DockAnchor { @@ -640,16 +668,6 @@ impl Settings { }) } - fn terminal_setting(&self, f: F) -> R - where - F: Fn(&TerminalSettings) -> Option<&R>, - { - f(&self.terminal_overrides) - .or_else(|| f(&self.terminal_defaults)) - .cloned() - .unwrap_or_else(|| R::default()) - } - pub fn telemetry(&self) -> TelemetrySettings { TelemetrySettings { diagnostics: Some(self.telemetry_diagnostics()), @@ -671,20 +689,33 @@ impl Settings { .expect("missing default") } + fn terminal_setting(&self, f: F) -> R + where + F: Fn(&TerminalSettings) -> Option, + { + None.or_else(|| f(&self.terminal_overrides)) + .or_else(|| f(&self.terminal_defaults)) + .expect("missing default") + } + + pub fn terminal_line_height(&self) -> f32 { + self.terminal_setting(|terminal_setting| terminal_setting.line_height()) + } + pub fn terminal_scroll(&self) -> AlternateScroll { - self.terminal_setting(|terminal_setting| terminal_setting.alternate_scroll.as_ref()) + self.terminal_setting(|terminal_setting| terminal_setting.alternate_scroll.to_owned()) } pub fn terminal_shell(&self) -> Shell { - self.terminal_setting(|terminal_setting| terminal_setting.shell.as_ref()) + self.terminal_setting(|terminal_setting| terminal_setting.shell.to_owned()) } pub fn terminal_env(&self) -> HashMap { - self.terminal_setting(|terminal_setting| terminal_setting.env.as_ref()) + self.terminal_setting(|terminal_setting| terminal_setting.env.to_owned()) } pub fn terminal_strategy(&self) -> WorkingDirectory { - self.terminal_setting(|terminal_setting| terminal_setting.working_directory.as_ref()) + self.terminal_setting(|terminal_setting| terminal_setting.working_directory.to_owned()) } #[cfg(any(test, feature = "test-support"))] diff --git a/crates/terminal_view/src/terminal_element.rs b/crates/terminal_view/src/terminal_element.rs index 252ab128be..af8f303bbd 100644 --- a/crates/terminal_view/src/terminal_element.rs +++ b/crates/terminal_view/src/terminal_element.rs @@ -567,7 +567,7 @@ impl Element for TerminalElement { let selection_color = settings.theme.editor.selection.selection; let match_color = settings.theme.search.match_background; let dimensions = { - let line_height = font_cache.line_height(text_style.font_size); + let line_height = text_style.font_size * settings.terminal_line_height(); let cell_width = font_cache.em_advance(text_style.font_id, text_style.font_size); TerminalSize::new(line_height, cell_width, constraint.max) };