macos: add title override to restorable state

pull/9879/head
Mitchell Hashimoto 2025-12-11 16:40:09 -08:00
parent 6105344c31
commit 50bbced0c9
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
2 changed files with 12 additions and 6 deletions

View File

@ -83,7 +83,7 @@ class BaseTerminalController: NSWindowController,
/// An override title for the tab/window set by the user via prompt_tab_title.
/// When set, this takes precedence over the computed title from the terminal.
var tabTitleOverride: String? = nil {
var titleOverride: String? = nil {
didSet { applyTitleToWindow() }
}
@ -344,7 +344,7 @@ class BaseTerminalController: NSWindowController,
alert.alertStyle = .informational
let textField = NSTextField(frame: NSRect(x: 0, y: 0, width: 250, height: 24))
textField.stringValue = tabTitleOverride ?? window.title
textField.stringValue = titleOverride ?? window.title
alert.accessoryView = textField
alert.addButton(withTitle: "OK")
@ -358,9 +358,9 @@ class BaseTerminalController: NSWindowController,
let newTitle = textField.stringValue
if newTitle.isEmpty {
self.tabTitleOverride = nil
self.titleOverride = nil
} else {
self.tabTitleOverride = newTitle
self.titleOverride = newTitle
}
}
}
@ -764,7 +764,7 @@ class BaseTerminalController: NSWindowController,
private func applyTitleToWindow() {
guard let window else { return }
window.title = tabTitleOverride ?? lastComputedTitle
window.title = titleOverride ?? lastComputedTitle
}
func pwdDidChange(to: URL?) {

View File

@ -4,18 +4,20 @@ import Cocoa
class TerminalRestorableState: Codable {
static let selfKey = "state"
static let versionKey = "version"
static let version: Int = 6
static let version: Int = 7
let focusedSurface: String?
let surfaceTree: SplitTree<Ghostty.SurfaceView>
let effectiveFullscreenMode: FullscreenMode?
let tabColor: TerminalTabColor
let titleOverride: String?
init(from controller: TerminalController) {
self.focusedSurface = controller.focusedSurface?.id.uuidString
self.surfaceTree = controller.surfaceTree
self.effectiveFullscreenMode = controller.fullscreenStyle?.fullscreenMode
self.tabColor = (controller.window as? TerminalWindow)?.tabColor ?? .none
self.titleOverride = controller.titleOverride
}
init?(coder aDecoder: NSCoder) {
@ -34,6 +36,7 @@ class TerminalRestorableState: Codable {
self.focusedSurface = v.value.focusedSurface
self.effectiveFullscreenMode = v.value.effectiveFullscreenMode
self.tabColor = v.value.tabColor
self.titleOverride = v.value.titleOverride
}
func encode(with coder: NSCoder) {
@ -100,6 +103,9 @@ class TerminalWindowRestoration: NSObject, NSWindowRestoration {
// Restore our tab color
(window as? TerminalWindow)?.tabColor = state.tabColor
// Restore the tab title override
c.titleOverride = state.titleOverride
// Setup our restored state on the controller
// Find the focused surface in surfaceTree
if let focusedStr = state.focusedSurface {