Setting to show/hide terminal title (#8559)

This PR adds settings for hiding title (breadcrumbs) from the terminal
toolbar. If the title is hidden, the toolbar disappears completely.

Example:

```json
"terminal": {
  "toolbar": {
    "title": true,
  }
}
```

[The PR that added the "toolbar"
setting](https://github.com/zed-industries/zed/pull/7338) didn't affect
toolbars of the terminals that are placed in the editor pane. This PR
fixes that.


Release Notes:

- Added support for configuring the terminal toolbar ([8125](https://github.com/zed-industries/zed/issues/8125))
This commit is contained in:
Andrew Lygin 2024-03-02 00:37:02 +03:00 committed by GitHub
parent 400fb12f7e
commit 37f7957826
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 59 additions and 2 deletions

View file

@ -472,6 +472,10 @@
// Can also be 'csh', 'fish', and `nushell` // Can also be 'csh', 'fish', and `nushell`
"activate_script": "default" "activate_script": "default"
} }
},
"toolbar": {
// Whether to display the terminal title in its toolbar.
"title": true
} }
// Set the terminal's font size. If this option is not included, // Set the terminal's font size. If this option is not included,
// the terminal will default to matching the buffer's font size. // the terminal will default to matching the buffer's font size.

View file

@ -18,6 +18,11 @@ pub enum TerminalDockPosition {
Right, Right,
} }
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct Toolbar {
pub title: bool,
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct TerminalSettings { pub struct TerminalSettings {
pub shell: Shell, pub shell: Shell,
@ -36,6 +41,7 @@ pub struct TerminalSettings {
pub default_height: Pixels, pub default_height: Pixels,
pub detect_venv: VenvSettings, pub detect_venv: VenvSettings,
pub max_scroll_history_lines: Option<usize>, pub max_scroll_history_lines: Option<usize>,
pub toolbar: Toolbar,
} }
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
@ -155,6 +161,8 @@ pub struct TerminalSettingsContent {
/// ///
/// Default: 10_000 /// Default: 10_000
pub max_scroll_history_lines: Option<usize>, pub max_scroll_history_lines: Option<usize>,
/// Toolbar related settings
pub toolbar: Option<ToolbarContent>,
} }
impl settings::Settings for TerminalSettings { impl settings::Settings for TerminalSettings {
@ -274,3 +282,12 @@ pub enum WorkingDirectory {
/// this platform's home directory (if it can be found). /// this platform's home directory (if it can be found).
Always { directory: String }, Always { directory: String },
} }
// Toolbar related settings
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct ToolbarContent {
/// Whether to display the terminal title in its toolbar.
///
/// Default: true
pub title: Option<bool>,
}

View file

@ -13,6 +13,7 @@ use gpui::{
use language::Bias; use language::Bias;
use persistence::TERMINAL_DB; use persistence::TERMINAL_DB;
use project::{search::SearchQuery, Fs, LocalWorktree, Metadata, Project}; use project::{search::SearchQuery, Fs, LocalWorktree, Metadata, Project};
use settings::SettingsStore;
use terminal::{ use terminal::{
alacritty_terminal::{ alacritty_terminal::{
index::Point, index::Point,
@ -90,6 +91,7 @@ pub struct TerminalView {
blink_epoch: usize, blink_epoch: usize,
can_navigate_to_selected_word: bool, can_navigate_to_selected_word: bool,
workspace_id: WorkspaceId, workspace_id: WorkspaceId,
show_title: bool,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
_terminal_subscriptions: Vec<Subscription>, _terminal_subscriptions: Vec<Subscription>,
} }
@ -165,7 +167,12 @@ impl TerminalView {
blink_epoch: 0, blink_epoch: 0,
can_navigate_to_selected_word: false, can_navigate_to_selected_word: false,
workspace_id, workspace_id,
_subscriptions: vec![focus_in, focus_out], show_title: TerminalSettings::get_global(cx).toolbar.title,
_subscriptions: vec![
focus_in,
focus_out,
cx.observe_global::<SettingsStore>(Self::settings_changed),
],
_terminal_subscriptions: terminal_subscriptions, _terminal_subscriptions: terminal_subscriptions,
} }
} }
@ -208,6 +215,12 @@ impl TerminalView {
self.context_menu = Some((context_menu, position, subscription)); self.context_menu = Some((context_menu, position, subscription));
} }
fn settings_changed(&mut self, cx: &mut ViewContext<Self>) {
let settings = TerminalSettings::get_global(cx);
self.show_title = settings.toolbar.title;
cx.notify();
}
fn show_character_palette(&mut self, _: &ShowCharacterPalette, cx: &mut ViewContext<Self>) { fn show_character_palette(&mut self, _: &ShowCharacterPalette, cx: &mut ViewContext<Self>) {
if !self if !self
.terminal .terminal
@ -832,7 +845,11 @@ impl Item for TerminalView {
} }
fn breadcrumb_location(&self) -> ToolbarItemLocation { fn breadcrumb_location(&self) -> ToolbarItemLocation {
ToolbarItemLocation::PrimaryLeft if self.show_title {
ToolbarItemLocation::PrimaryLeft
} else {
ToolbarItemLocation::Hidden
}
} }
fn breadcrumbs(&self, _: &theme::Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> { fn breadcrumbs(&self, _: &theme::Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {

View file

@ -681,6 +681,9 @@ These values take in the same options as the root-level settings with the same n
"font_size": null, "font_size": null,
"option_as_meta": false, "option_as_meta": false,
"shell": {}, "shell": {},
"toolbar": {
"title": true
},
"working_directory": "current_project_directory" "working_directory": "current_project_directory"
} }
``` ```
@ -839,6 +842,22 @@ See Buffer Font Features
} }
``` ```
## Terminal Toolbar
- Description: Whether or not to show various elements in the terminal toolbar. It only affects terminals placed in the editor pane.
- Setting: `toolbar`
- Default:
```json
"toolbar": {
"title": true,
},
```
**Options**
At the moment, only the `title` option is available, it controls displaying of the terminal title that can be changed via `PROMPT_COMMAND`. If the title is hidden, the terminal toolbar is not displayed.
### Working Directory ### Working Directory
- Description: What working directory to use when launching the terminal. - Description: What working directory to use when launching the terminal.