Only show breadcrumbs for terminals when there's a title (#20997)

Closes https://github.com/zed-industries/zed/issues/20475

Release Notes:

- Fixed terminal title and breadcrumbs behavior

---------

Co-authored-by: Thorsten Ball <thorsten@zed.dev>
This commit is contained in:
Kirill Bulatov 2024-11-21 19:57:09 +02:00 committed by GitHub
parent 395e25be25
commit 5ff49db92f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 43 additions and 23 deletions

1
Cargo.lock generated
View file

@ -12282,6 +12282,7 @@ name = "terminal_view"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"breadcrumbs",
"client", "client",
"collections", "collections",
"db", "db",

View file

@ -847,8 +847,12 @@
} }
}, },
"toolbar": { "toolbar": {
// Whether to display the terminal title in its toolbar. // Whether to display the terminal title in its toolbar's breadcrumbs.
"title": true // Only shown if the terminal title is not empty.
//
// The shell running in the terminal needs to be configured to emit the title.
// Example: `echo -e "\e]2;New Title\007";`
"breadcrumbs": 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

@ -776,7 +776,7 @@ impl Item for ProjectDiagnosticsEditor {
} }
} }
fn breadcrumb_location(&self) -> ToolbarItemLocation { fn breadcrumb_location(&self, _: &AppContext) -> ToolbarItemLocation {
ToolbarItemLocation::PrimaryLeft ToolbarItemLocation::PrimaryLeft
} }

View file

@ -841,7 +841,7 @@ impl Item for Editor {
self.pixel_position_of_newest_cursor self.pixel_position_of_newest_cursor
} }
fn breadcrumb_location(&self) -> ToolbarItemLocation { fn breadcrumb_location(&self, _: &AppContext) -> ToolbarItemLocation {
if self.show_breadcrumbs { if self.show_breadcrumbs {
ToolbarItemLocation::PrimaryLeft ToolbarItemLocation::PrimaryLeft
} else { } else {

View file

@ -116,7 +116,7 @@ impl Item for ImageView {
.map(Icon::from_path) .map(Icon::from_path)
} }
fn breadcrumb_location(&self) -> ToolbarItemLocation { fn breadcrumb_location(&self, _: &AppContext) -> ToolbarItemLocation {
ToolbarItemLocation::PrimaryLeft ToolbarItemLocation::PrimaryLeft
} }

View file

@ -536,7 +536,7 @@ impl Item for ProjectSearchView {
} }
} }
fn breadcrumb_location(&self) -> ToolbarItemLocation { fn breadcrumb_location(&self, _: &AppContext) -> ToolbarItemLocation {
if self.has_matches() { if self.has_matches() {
ToolbarItemLocation::Secondary ToolbarItemLocation::Secondary
} else { } else {

View file

@ -21,7 +21,7 @@ pub enum TerminalDockPosition {
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct Toolbar { pub struct Toolbar {
pub title: bool, pub breadcrumbs: bool,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
@ -286,10 +286,14 @@ pub enum WorkingDirectory {
// Toolbar related settings // Toolbar related settings
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct ToolbarContent { pub struct ToolbarContent {
/// Whether to display the terminal title in its toolbar. /// Whether to display the terminal title in breadcrumbs inside the terminal pane.
/// Only shown if the terminal title is not empty.
///
/// The shell running in the terminal needs to be configured to emit the title.
/// Example: `echo -e "\e]2;New Title\007";`
/// ///
/// Default: true /// Default: true
pub title: Option<bool>, pub breadcrumbs: Option<bool>,
} }
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]

View file

@ -14,8 +14,9 @@ doctest = false
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true
db.workspace = true breadcrumbs.workspace = true
collections.workspace = true collections.workspace = true
db.workspace = true
dirs.workspace = true dirs.workspace = true
editor.workspace = true editor.workspace = true
futures.workspace = true futures.workspace = true

View file

@ -1,6 +1,7 @@
use std::{ops::ControlFlow, path::PathBuf, sync::Arc}; use std::{ops::ControlFlow, path::PathBuf, sync::Arc};
use crate::{default_working_directory, TerminalView}; use crate::{default_working_directory, TerminalView};
use breadcrumbs::Breadcrumbs;
use collections::{HashMap, HashSet}; use collections::{HashMap, HashSet};
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use futures::future::join_all; use futures::future::join_all;
@ -138,8 +139,11 @@ impl TerminalPanel {
ControlFlow::Break(()) ControlFlow::Break(())
}); });
let buffer_search_bar = cx.new_view(search::BufferSearchBar::new); let buffer_search_bar = cx.new_view(search::BufferSearchBar::new);
pane.toolbar() let breadcrumbs = cx.new_view(|_| Breadcrumbs::new());
.update(cx, |toolbar, cx| toolbar.add_item(buffer_search_bar, cx)); pane.toolbar().update(cx, |toolbar, cx| {
toolbar.add_item(buffer_search_bar, cx);
toolbar.add_item(breadcrumbs, cx);
});
pane pane
}); });
let subscriptions = vec![ let subscriptions = vec![

View file

@ -109,7 +109,7 @@ pub struct TerminalView {
blink_epoch: usize, blink_epoch: usize,
can_navigate_to_selected_word: bool, can_navigate_to_selected_word: bool,
workspace_id: Option<WorkspaceId>, workspace_id: Option<WorkspaceId>,
show_title: bool, show_breadcrumbs: bool,
block_below_cursor: Option<Rc<BlockProperties>>, block_below_cursor: Option<Rc<BlockProperties>>,
scroll_top: Pixels, scroll_top: Pixels,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
@ -189,7 +189,7 @@ impl TerminalView {
blink_epoch: 0, blink_epoch: 0,
can_navigate_to_selected_word: false, can_navigate_to_selected_word: false,
workspace_id, workspace_id,
show_title: TerminalSettings::get_global(cx).toolbar.title, show_breadcrumbs: TerminalSettings::get_global(cx).toolbar.breadcrumbs,
block_below_cursor: None, block_below_cursor: None,
scroll_top: Pixels::ZERO, scroll_top: Pixels::ZERO,
_subscriptions: vec![ _subscriptions: vec![
@ -259,7 +259,7 @@ impl TerminalView {
fn settings_changed(&mut self, cx: &mut ViewContext<Self>) { fn settings_changed(&mut self, cx: &mut ViewContext<Self>) {
let settings = TerminalSettings::get_global(cx); let settings = TerminalSettings::get_global(cx);
self.show_title = settings.toolbar.title; self.show_breadcrumbs = settings.toolbar.breadcrumbs;
let new_cursor_shape = settings.cursor_shape.unwrap_or_default(); let new_cursor_shape = settings.cursor_shape.unwrap_or_default();
let old_cursor_shape = self.cursor_shape; let old_cursor_shape = self.cursor_shape;
@ -1145,8 +1145,8 @@ impl Item for TerminalView {
Some(Box::new(handle.clone())) Some(Box::new(handle.clone()))
} }
fn breadcrumb_location(&self) -> ToolbarItemLocation { fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation {
if self.show_title { if self.show_breadcrumbs && !self.terminal().read(cx).breadcrumb_text.trim().is_empty() {
ToolbarItemLocation::PrimaryLeft ToolbarItemLocation::PrimaryLeft
} else { } else {
ToolbarItemLocation::Hidden ToolbarItemLocation::Hidden

View file

@ -278,7 +278,7 @@ pub trait Item: FocusableView + EventEmitter<Self::Event> {
None None
} }
fn breadcrumb_location(&self) -> ToolbarItemLocation { fn breadcrumb_location(&self, _: &AppContext) -> ToolbarItemLocation {
ToolbarItemLocation::Hidden ToolbarItemLocation::Hidden
} }
@ -827,7 +827,7 @@ impl<T: Item> ItemHandle for View<T> {
} }
fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation { fn breadcrumb_location(&self, cx: &AppContext) -> ToolbarItemLocation {
self.read(cx).breadcrumb_location() self.read(cx).breadcrumb_location(cx)
} }
fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> { fn breadcrumbs(&self, theme: &Theme, cx: &AppContext) -> Option<Vec<BreadcrumbText>> {

View file

@ -1628,7 +1628,7 @@ List of `integer` column numbers
"button": false, "button": false,
"shell": {}, "shell": {},
"toolbar": { "toolbar": {
"title": true "breadcrumbs": true
}, },
"working_directory": "current_project_directory" "working_directory": "current_project_directory"
} }
@ -1946,7 +1946,7 @@ Disable with:
## Terminal: Toolbar ## Terminal: Toolbar
- Description: Whether or not to show various elements in the terminal toolbar. It only affects terminals placed in the editor pane. - Description: Whether or not to show various elements in the terminal toolbar.
- Setting: `toolbar` - Setting: `toolbar`
- Default: - Default:
@ -1954,7 +1954,7 @@ Disable with:
{ {
"terminal": { "terminal": {
"toolbar": { "toolbar": {
"title": true "breadcrumbs": true
} }
} }
} }
@ -1962,7 +1962,13 @@ Disable with:
**Options** **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. At the moment, only the `breadcrumbs` option is available, it controls displaying of the terminal title that can be changed via `PROMPT_COMMAND`.
If the terminal title is empty, the breadcrumbs won't be shown.
The shell running in the terminal needs to be configured to emit the title.
Example command to set the title: `echo -e "\e]2;New Title\007";`
### Terminal: Button ### Terminal: Button