Implement tab title override

This commit is contained in:
Jeremy Soller 2024-02-20 10:21:30 -07:00
parent f6d696f7d6
commit 290b7b5993
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
3 changed files with 48 additions and 12 deletions

View file

@ -1,3 +1,5 @@
new-terminal = New terminal
# Context Pages # Context Pages
## Profiles ## Profiles

View file

@ -862,17 +862,12 @@ impl App {
Some(colors) => { Some(colors) => {
let current_pane = self.pane_model.focus; let current_pane = self.pane_model.focus;
if let Some(tab_model) = self.pane_model.active_mut() { if let Some(tab_model) = self.pane_model.active_mut() {
let entity = tab_model
.insert()
.text("New Terminal")
.closable()
.activate()
.id();
// Use the profile options, startup options, or defaults // Use the profile options, startup options, or defaults
let options = match profile_id_opt let (options, tab_title_override) = match profile_id_opt
.and_then(|profile_id| self.config.profiles.get(&profile_id)) .and_then(|profile_id| self.config.profiles.get(&profile_id))
{ {
Some(profile) => { Some(profile) => {
if !profile.tab_title.is_empty() {}
let mut shell = None; let mut shell = None;
if let Some(mut args) = shlex::split(&profile.command) { if let Some(mut args) = shlex::split(&profile.command) {
if !args.is_empty() { if !args.is_empty() {
@ -880,16 +875,32 @@ impl App {
shell = Some(tty::Shell::new(command, args)); shell = Some(tty::Shell::new(command, args));
} }
} }
tty::Options { let options = tty::Options {
shell, shell,
//TODO: configurable working directory? //TODO: configurable working directory?
working_directory: None, working_directory: None,
//TODO: configurable hold (keep open when child exits)? //TODO: configurable hold (keep open when child exits)?
hold: false, hold: false,
} };
let tab_title_override = if !profile.tab_title.is_empty() {
Some(profile.tab_title.clone())
} else {
None
};
(options, tab_title_override)
} }
None => self.startup_options.take().unwrap_or_default(), None => (self.startup_options.take().unwrap_or_default(), None),
}; };
let entity = tab_model
.insert()
.text(
tab_title_override
.clone()
.unwrap_or_else(|| fl!("new-terminal")),
)
.closable()
.activate()
.id();
match Terminal::new( match Terminal::new(
current_pane, current_pane,
entity, entity,
@ -899,6 +910,7 @@ impl App {
&self.config, &self.config,
*colors, *colors,
profile_id_opt, profile_id_opt,
tab_title_override,
) { ) {
Ok(mut terminal) => { Ok(mut terminal) => {
terminal.set_config(&self.config, &self.themes, self.zoom_adj); terminal.set_config(&self.config, &self.themes, self.zoom_adj);
@ -1669,7 +1681,17 @@ impl Application for App {
} }
TermEvent::ResetTitle => { TermEvent::ResetTitle => {
if let Some(tab_model) = self.pane_model.panes.get_mut(pane) { if let Some(tab_model) = self.pane_model.panes.get_mut(pane) {
tab_model.text_set(entity, "New Terminal"); let tab_title_override =
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
let terminal = terminal.lock().unwrap();
terminal.tab_title_override.clone()
} else {
None
};
tab_model.text_set(
entity,
tab_title_override.unwrap_or_else(|| fl!("new-terminal")),
);
} }
return self.update_title(Some(pane)); return self.update_title(Some(pane));
} }
@ -1684,7 +1706,16 @@ impl Application for App {
} }
TermEvent::Title(title) => { TermEvent::Title(title) => {
if let Some(tab_model) = self.pane_model.panes.get_mut(pane) { if let Some(tab_model) = self.pane_model.panes.get_mut(pane) {
tab_model.text_set(entity, title); let has_override =
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
let terminal = terminal.lock().unwrap();
terminal.tab_title_override.is_some()
} else {
false
};
if !has_override {
tab_model.text_set(entity, title);
}
} }
return self.update_title(Some(pane)); return self.update_title(Some(pane));
} }

View file

@ -194,6 +194,7 @@ pub struct Terminal {
pub metadata_set: IndexSet<Metadata>, pub metadata_set: IndexSet<Metadata>,
pub needs_update: bool, pub needs_update: bool,
pub profile_id_opt: Option<ProfileId>, pub profile_id_opt: Option<ProfileId>,
pub tab_title_override: Option<String>,
pub term: Arc<FairMutex<Term<EventProxy>>>, pub term: Arc<FairMutex<Term<EventProxy>>>,
bold_font_weight: Weight, bold_font_weight: Weight,
buffer: Arc<Buffer>, buffer: Arc<Buffer>,
@ -219,6 +220,7 @@ impl Terminal {
app_config: &AppConfig, app_config: &AppConfig,
colors: Colors, colors: Colors,
profile_id_opt: Option<ProfileId>, profile_id_opt: Option<ProfileId>,
tab_title_override: Option<String>,
) -> Result<Self, io::Error> { ) -> Result<Self, io::Error> {
let font_stretch = app_config.typed_font_stretch(); let font_stretch = app_config.typed_font_stretch();
let font_weight = app_config.font_weight; let font_weight = app_config.font_weight;
@ -293,6 +295,7 @@ impl Terminal {
search_regex_opt: None, search_regex_opt: None,
search_value: String::new(), search_value: String::new(),
size, size,
tab_title_override,
term, term,
use_bright_bold, use_bright_bold,
}) })