macOS: Change Tab Title (#9879)

This adds the ability to change a _tab_ title. The previous
functionality was tied to a specific _surface_. A tab title will stick
to the current tab regardless of active splits and so on.

This follows the nomenclature that macOS terminal app does which is
"title vs terminal title" (although we explicitly use "tab" in various
places, I may remove that in the future).

**This is macOS only. GTK is tracked here: #9880**. I did macOS only
because thats the machine I'm on. It'll be trivial to add this to GTK,
too.

## Demo


https://github.com/user-attachments/assets/d9446785-d919-4212-8553-db50c56c8c2f

(The option is also in the main menu, the context menu, and the command
palette)

## AI Disclosure

This PR was done fully with Amp, I didn't write a single line of code at
the time of writing this PR description. I reviewed everything though
and fully understand it all. Its a mimic more or less of the prompt
surface title work (although we did unify some stuff like the apprt
action).
This commit is contained in:
Mitchell Hashimoto
2025-12-11 16:53:50 -08:00
committed by GitHub
14 changed files with 187 additions and 35 deletions

View File

@@ -5183,7 +5183,13 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
.prompt_surface_title => return try self.rt_app.performAction(
.{ .surface = self },
.prompt_title,
{},
.surface,
),
.prompt_tab_title => return try self.rt_app.performAction(
.{ .surface = self },
.prompt_title,
.tab,
),
.clear_screen => {

View File

@@ -189,8 +189,9 @@ pub const Action = union(Key) {
set_title: SetTitle,
/// Set the title of the target to a prompted value. It is up to
/// the apprt to prompt.
prompt_title,
/// the apprt to prompt. The value specifies whether to prompt for the
/// surface title or the tab title.
prompt_title: PromptTitle,
/// The current working directory has changed for the target terminal.
pwd: Pwd,
@@ -536,6 +537,12 @@ pub const MouseVisibility = enum(c_int) {
hidden,
};
/// Whether to prompt for the surface title or tab title.
pub const PromptTitle = enum(c_int) {
surface,
tab,
};
pub const MouseOverLink = struct {
url: [:0]const u8,

View File

@@ -693,7 +693,7 @@ pub const Application = extern struct {
.progress_report => return Action.progressReport(target, value),
.prompt_title => return Action.promptTitle(target),
.prompt_title => return Action.promptTitle(target, value),
.quit => self.quit(),
@@ -2250,12 +2250,18 @@ const Action = struct {
};
}
pub fn promptTitle(target: apprt.Target) bool {
switch (target) {
.app => return false,
.surface => |v| {
v.rt_surface.surface.promptTitle();
return true;
pub fn promptTitle(target: apprt.Target, value: apprt.action.PromptTitle) bool {
switch (value) {
.surface => switch (target) {
.app => return false,
.surface => |v| {
v.rt_surface.surface.promptTitle();
return true;
},
},
.tab => {
// GTK does not yet support tab title prompting
return false;
},
}
}

View File

@@ -519,6 +519,11 @@ pub const Action = union(enum) {
/// version can be found by running `ghostty +version`.
prompt_surface_title,
/// Change the title of the current tab/window via a pop-up prompt. The
/// title set via this prompt overrides any title set by the terminal
/// and persists across focus changes within the tab.
prompt_tab_title,
/// Create a new split in the specified direction.
///
/// Valid arguments:
@@ -1191,6 +1196,7 @@ pub const Action = union(enum) {
.reset_font_size,
.set_font_size,
.prompt_surface_title,
.prompt_tab_title,
.clear_screen,
.select_all,
.scroll_to_top,

View File

@@ -413,10 +413,16 @@ fn actionCommands(action: Action.Key) []const Command {
.prompt_surface_title => comptime &.{.{
.action = .prompt_surface_title,
.title = "Change Title...",
.title = "Change Terminal Title...",
.description = "Prompt for a new title for the current terminal.",
}},
.prompt_tab_title => comptime &.{.{
.action = .prompt_tab_title,
.title = "Change Tab Title...",
.description = "Prompt for a new title for the current tab.",
}},
.new_split => comptime &.{
.{
.action = .{ .new_split = .left },