From 27db2eb8dd845929f5ac45a3d1bad9f71a78d58e Mon Sep 17 00:00:00 2001 From: Austin Wang Date: Mon, 30 Mar 2026 02:05:13 -0700 Subject: [PATCH] Add reset-terminal terminal menu workaround (#2349) --- Resources/Localizable.xcstrings | 102 ++++++++++++++++++++++++++++++ Sources/GhosttyTerminalView.swift | 37 +++++++++-- 2 files changed, 134 insertions(+), 5 deletions(-) diff --git a/Resources/Localizable.xcstrings b/Resources/Localizable.xcstrings index e07ac5ad..15a9dba4 100644 --- a/Resources/Localizable.xcstrings +++ b/Resources/Localizable.xcstrings @@ -84898,6 +84898,108 @@ } } } + }, + "terminalContextMenu.copy": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Copy" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "コピー" + } + } + } + }, + "terminalContextMenu.paste": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Paste" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "ペースト" + } + } + } + }, + "terminalContextMenu.resetTerminal": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Reset Terminal" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "ターミナルをリセット" + } + } + } + }, + "terminalContextMenu.splitHorizontally": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Split Horizontally" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "水平に分割" + } + } + } + }, + "terminalContextMenu.splitVertically": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Split Vertically" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "垂直に分割" + } + } + } + }, + "terminalContextMenu.triggerFlash": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Trigger Flash" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "フラッシュを発火" + } + } + } } } } diff --git a/Sources/GhosttyTerminalView.swift b/Sources/GhosttyTerminalView.swift index b4f6e41a..625bc5a4 100644 --- a/Sources/GhosttyTerminalView.swift +++ b/Sources/GhosttyTerminalView.swift @@ -6445,19 +6445,31 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations { let menu = NSMenu() if onTriggerFlash != nil { - let flashItem = menu.addItem(withTitle: "Trigger Flash", action: #selector(triggerFlash(_:)), keyEquivalent: "") + let flashItem = menu.addItem( + withTitle: String(localized: "terminalContextMenu.triggerFlash", defaultValue: "Trigger Flash"), + action: #selector(triggerFlash(_:)), + keyEquivalent: "" + ) flashItem.target = self menu.addItem(.separator()) } if ghostty_surface_has_selection(surface) { - let item = menu.addItem(withTitle: "Copy", action: #selector(copy(_:)), keyEquivalent: "") + let item = menu.addItem( + withTitle: String(localized: "terminalContextMenu.copy", defaultValue: "Copy"), + action: #selector(copy(_:)), + keyEquivalent: "" + ) item.target = self } - let pasteItem = menu.addItem(withTitle: "Paste", action: #selector(paste(_:)), keyEquivalent: "") + let pasteItem = menu.addItem( + withTitle: String(localized: "terminalContextMenu.paste", defaultValue: "Paste"), + action: #selector(paste(_:)), + keyEquivalent: "" + ) pasteItem.target = self menu.addItem(.separator()) let splitHorizontallyItem = menu.addItem( - withTitle: "Split Horizontally", + withTitle: String(localized: "terminalContextMenu.splitHorizontally", defaultValue: "Split Horizontally"), action: #selector(splitHorizontally(_:)), keyEquivalent: "d" ) @@ -6469,7 +6481,7 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations { ) let splitVerticallyItem = menu.addItem( - withTitle: "Split Vertically", + withTitle: String(localized: "terminalContextMenu.splitVertically", defaultValue: "Split Vertically"), action: #selector(splitVertically(_:)), keyEquivalent: "d" ) @@ -6479,6 +6491,17 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations { systemSymbolName: "rectangle.righthalf.inset.filled", accessibilityDescription: nil ) + menu.addItem(.separator()) + let resetTerminalItem = menu.addItem( + withTitle: String(localized: "terminalContextMenu.resetTerminal", defaultValue: "Reset Terminal"), + action: #selector(resetTerminal(_:)), + keyEquivalent: "" + ) + resetTerminalItem.target = self + resetTerminalItem.image = NSImage( + systemSymbolName: "arrow.trianglehead.2.clockwise", + accessibilityDescription: nil + ) return menu } @@ -6516,6 +6539,10 @@ class GhosttyNSView: NSView, NSUserInterfaceValidations { onTriggerFlash?() } + @objc private func resetTerminal(_ sender: Any?) { + _ = performBindingAction("reset") + } + override func mouseMoved(with event: NSEvent) { maybeRequestFirstResponderForMouseFocus() guard let surface = surface else { return }