Use terminal titles for buttons
This commit is contained in:
parent
c80942ea00
commit
0a3f0c5252
3 changed files with 39 additions and 36 deletions
|
@ -32,6 +32,7 @@ use mappings::mouse::{
|
||||||
|
|
||||||
use procinfo::LocalProcessInfo;
|
use procinfo::LocalProcessInfo;
|
||||||
use settings::{AlternateScroll, Settings, Shell, TerminalBlink};
|
use settings::{AlternateScroll, Settings, Shell, TerminalBlink};
|
||||||
|
use util::truncate_and_trailoff;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
cmp::min,
|
cmp::min,
|
||||||
|
@ -1169,6 +1170,38 @@ impl Terminal {
|
||||||
all_search_matches(&term, &searcher).collect()
|
all_search_matches(&term, &searcher).collect()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn title(&self) -> String {
|
||||||
|
self.foreground_process_info
|
||||||
|
.as_ref()
|
||||||
|
.map(|fpi| {
|
||||||
|
format!(
|
||||||
|
"{} — {}",
|
||||||
|
truncate_and_trailoff(
|
||||||
|
&fpi.cwd
|
||||||
|
.file_name()
|
||||||
|
.map(|name| name.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_default(),
|
||||||
|
25
|
||||||
|
),
|
||||||
|
truncate_and_trailoff(
|
||||||
|
&{
|
||||||
|
format!(
|
||||||
|
"{}{}",
|
||||||
|
fpi.name,
|
||||||
|
if fpi.argv.len() >= 1 {
|
||||||
|
format!(" {}", (&fpi.argv[1..]).join(" "))
|
||||||
|
} else {
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
25
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| "Terminal".to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Terminal {
|
impl Drop for Terminal {
|
||||||
|
|
|
@ -30,7 +30,7 @@ use terminal::{
|
||||||
},
|
},
|
||||||
Event, Terminal,
|
Event, Terminal,
|
||||||
};
|
};
|
||||||
use util::{truncate_and_trailoff, ResultExt};
|
use util::ResultExt;
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{Item, ItemEvent},
|
item::{Item, ItemEvent},
|
||||||
notifications::NotifyResultExt,
|
notifications::NotifyResultExt,
|
||||||
|
@ -547,38 +547,7 @@ impl Item for TerminalView {
|
||||||
tab_theme: &theme::Tab,
|
tab_theme: &theme::Tab,
|
||||||
cx: &gpui::AppContext,
|
cx: &gpui::AppContext,
|
||||||
) -> ElementBox {
|
) -> ElementBox {
|
||||||
let title = self
|
let title = self.terminal().read(cx).title();
|
||||||
.terminal()
|
|
||||||
.read(cx)
|
|
||||||
.foreground_process_info
|
|
||||||
.as_ref()
|
|
||||||
.map(|fpi| {
|
|
||||||
format!(
|
|
||||||
"{} — {}",
|
|
||||||
truncate_and_trailoff(
|
|
||||||
&fpi.cwd
|
|
||||||
.file_name()
|
|
||||||
.map(|name| name.to_string_lossy().to_string())
|
|
||||||
.unwrap_or_default(),
|
|
||||||
25
|
|
||||||
),
|
|
||||||
truncate_and_trailoff(
|
|
||||||
&{
|
|
||||||
format!(
|
|
||||||
"{}{}",
|
|
||||||
fpi.name,
|
|
||||||
if fpi.argv.len() >= 1 {
|
|
||||||
format!(" {}", (&fpi.argv[1..]).join(" "))
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
25
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap_or_else(|| "Terminal".to_string());
|
|
||||||
|
|
||||||
Flex::row()
|
Flex::row()
|
||||||
.with_child(
|
.with_child(
|
||||||
|
|
|
@ -120,10 +120,11 @@ impl TerminalButton {
|
||||||
let local_terminal_handles = project.local_terminal_handles();
|
let local_terminal_handles = project.local_terminal_handles();
|
||||||
|
|
||||||
for local_terminal_handle in local_terminal_handles {
|
for local_terminal_handle in local_terminal_handles {
|
||||||
if let Some(_) = local_terminal_handle.upgrade(cx) {
|
if let Some(terminal) = local_terminal_handle.upgrade(cx) {
|
||||||
// TODO: Obtain the actual terminal "name" and put it in the menu
|
let title = terminal.read(cx).title();
|
||||||
|
|
||||||
// TODO: Replace the `NewTerminal` action with an action that instead focuses the selected terminal
|
// TODO: Replace the `NewTerminal` action with an action that instead focuses the selected terminal
|
||||||
menu_options.push(ContextMenuItem::item("Terminal", NewTerminal))
|
menu_options.push(ContextMenuItem::item(title, NewTerminal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue