From f9c14c55b40d2196702653a6ed0337ac77d5184d Mon Sep 17 00:00:00 2001 From: karei Date: Wed, 17 Jul 2024 22:15:56 +0300 Subject: [PATCH] macos: add button and menu item for opening scrollback file --- macos/Sources/App/macOS/AppDelegate.swift | 2 ++ macos/Sources/App/macOS/MainMenu.xib | 7 +++++++ macos/Sources/Features/Terminal/TerminalController.swift | 5 +++++ macos/Sources/Ghostty/Ghostty.App.swift | 7 +++++++ macos/Sources/Ghostty/SurfaceView_AppKit.swift | 1 + 5 files changed, 22 insertions(+) diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index 8b6b064a9..121e066ca 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -49,6 +49,7 @@ class AppDelegate: NSObject, @IBOutlet private var menuDecreaseFontSize: NSMenuItem? @IBOutlet private var menuResetFontSize: NSMenuItem? @IBOutlet private var menuTerminalInspector: NSMenuItem? + @IBOutlet private var menuOpenScrollback: NSMenuItem? @IBOutlet private var menuEqualizeSplits: NSMenuItem? @IBOutlet private var menuMoveSplitDividerUp: NSMenuItem? @@ -281,6 +282,7 @@ class AppDelegate: NSObject, syncMenuShortcut(action: "decrease_font_size:1", menuItem: self.menuDecreaseFontSize) syncMenuShortcut(action: "reset_font_size", menuItem: self.menuResetFontSize) syncMenuShortcut(action: "inspector:toggle", menuItem: self.menuTerminalInspector) + syncMenuShortcut(action: "write_scrollback_file:open", menuItem: self.menuOpenScrollback) // This menu item is NOT synced with the configuration because it disables macOS // global fullscreen keyboard shortcut. The shortcut in the Ghostty config will continue diff --git a/macos/Sources/App/macOS/MainMenu.xib b/macos/Sources/App/macOS/MainMenu.xib index bbfd59eae..56aa4c9b4 100644 --- a/macos/Sources/App/macOS/MainMenu.xib +++ b/macos/Sources/App/macOS/MainMenu.xib @@ -30,6 +30,7 @@ + @@ -215,6 +216,12 @@ + + + + + + diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 81b86a215..11b0ab8bf 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -604,6 +604,11 @@ class TerminalController: NSWindowController, NSWindowDelegate, guard let surface = focusedSurface?.surface else { return } ghostty.toggleTerminalInspector(surface: surface) } + + @IBAction func openScrollback(_ sender: Any) { + guard let surface = focusedSurface?.surface else { return } + ghostty.openScrollback(surface: surface) + } //MARK: - TerminalViewDelegate diff --git a/macos/Sources/Ghostty/Ghostty.App.swift b/macos/Sources/Ghostty/Ghostty.App.swift index 97a4aa0da..728094ae5 100644 --- a/macos/Sources/Ghostty/Ghostty.App.swift +++ b/macos/Sources/Ghostty/Ghostty.App.swift @@ -240,6 +240,13 @@ extension Ghostty { logger.warning("action failed action=\(action)") } } + + func openScrollback(surface: ghostty_surface_t) { + let action = "write_scrollback_file:open" + 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..bbab1b61e 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -952,6 +952,7 @@ extension Ghostty { menu.addItem(.separator()) menu.addItem(withTitle: "Toggle Terminal Inspector", action: #selector(TerminalController.toggleTerminalInspector(_:)), keyEquivalent: "") + menu.addItem(withTitle: "Open Scrollback", action: #selector(TerminalController.openScrollback(_:)), keyEquivalent: "") return menu }