Always show full command on terminal tab hover (#3934)

Deals with https://github.com/zed-industries/community/issues/1856

Release Notes:

- Fixed terminal tab tooltip being truncated
This commit is contained in:
Kirill Bulatov 2024-01-07 13:52:56 +02:00 committed by GitHub
commit eb9ddef083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 27 deletions

View File

@ -1311,34 +1311,33 @@ impl Terminal {
}) })
} }
pub fn title(&self) -> String { pub fn title(&self, truncate: bool) -> String {
self.foreground_process_info self.foreground_process_info
.as_ref() .as_ref()
.map(|fpi| { .map(|fpi| {
format!( let process_file = fpi
"{} — {}", .cwd
truncate_and_trailoff( .file_name()
&fpi.cwd .map(|name| name.to_string_lossy().to_string())
.file_name() .unwrap_or_default();
.map(|name| name.to_string_lossy().to_string()) let process_name = format!(
.unwrap_or_default(), "{}{}",
25 fpi.name,
), if fpi.argv.len() >= 1 {
truncate_and_trailoff( format!(" {}", (&fpi.argv[1..]).join(" "))
&{ } else {
format!( "".to_string()
"{}{}", }
fpi.name, );
if fpi.argv.len() >= 1 { let (process_file, process_name) = if truncate {
format!(" {}", (&fpi.argv[1..]).join(" ")) (
} else { truncate_and_trailoff(&process_file, 25),
"".to_string() truncate_and_trailoff(&process_name, 25),
}
)
},
25
) )
) } else {
(process_file, process_name)
};
format!("{process_file}{process_name}")
}) })
.unwrap_or_else(|| "Terminal".to_string()) .unwrap_or_else(|| "Terminal".to_string())
} }

View File

@ -680,7 +680,7 @@ impl Item for TerminalView {
type Event = ItemEvent; type Event = ItemEvent;
fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> { fn tab_tooltip_text(&self, cx: &AppContext) -> Option<SharedString> {
Some(self.terminal().read(cx).title().into()) Some(self.terminal().read(cx).title(false).into())
} }
fn tab_content( fn tab_content(
@ -689,8 +689,7 @@ impl Item for TerminalView {
selected: bool, selected: bool,
cx: &WindowContext, cx: &WindowContext,
) -> AnyElement { ) -> AnyElement {
let title = self.terminal().read(cx).title(); let title = self.terminal().read(cx).title(true);
h_stack() h_stack()
.gap_2() .gap_2()
.child(IconElement::new(Icon::Terminal)) .child(IconElement::new(Icon::Terminal))