From 9785130c03c0d4f243eadc3a0007bf1139b1db54 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 1 Aug 2024 14:58:03 -0700 Subject: [PATCH] macos: add "Reset Terminal" context menu option --- macos/Sources/Features/Terminal/TerminalController.swift | 5 +++++ macos/Sources/Ghostty/Ghostty.App.swift | 7 +++++++ macos/Sources/Ghostty/SurfaceView_AppKit.swift | 1 + 3 files changed, 13 insertions(+) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 3589e1a7b..ea27b976a 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -614,6 +614,11 @@ class TerminalController: NSWindowController, NSWindowDelegate, ghostty.toggleTerminalInspector(surface: surface) } + @objc func resetTerminal(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.resetTerminal(surface: surface) + } + //MARK: - TerminalViewDelegate func focusedSurfaceDidChange(to: Ghostty.SurfaceView?) { diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index 97a4aa0da..b4fe17f86 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -241,6 +241,13 @@ extension Ghostty { } } + func resetTerminal(surface: ghostty_surface_t) { + let action = "reset" + if (!ghostty_surface_binding_action(surface, action, UInt(action.count))) { + logger.warning("action failed action=\(action)") + } + } + #if os(iOS) // MARK: Ghostty Callbacks (iOS) diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index 26e41f61f..8a658242f 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -951,6 +951,7 @@ extension Ghostty { menu.addItem(withTitle: "Split Down", action: #selector(TerminalController.splitDown(_:)), keyEquivalent: "") menu.addItem(.separator()) + menu.addItem(withTitle: "Reset Terminal", action: #selector(TerminalController.resetTerminal(_:)), keyEquivalent: "") menu.addItem(withTitle: "Toggle Terminal Inspector", action: #selector(TerminalController.toggleTerminalInspector(_:)), keyEquivalent: "") return menu