mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-17 21:12:39 +00:00
macos: add terminals element to window and tab AppleScript classes
Expose terminal surfaces as elements on both ScriptWindow and ScriptTab, allowing AppleScript to enumerate terminals scoped to a specific window or tab (e.g. `terminals of window 1`, `terminals of tab 1 of window 1`). Changes: - Add `<element type="terminal">` to window and tab classes in Ghostty.sdef - Add `terminals` computed property and `valueInTerminalsWithUniqueID:` lookup to ScriptWindow (returns all surfaces across all tabs) - Add `terminals` computed property and `valueInTerminalsWithUniqueID:` lookup to ScriptTab (returns surfaces within that tab)
This commit is contained in:
@@ -73,6 +73,25 @@ final class ScriptWindow: NSObject {
|
||||
return ScriptTab(window: self, controller: controller)
|
||||
}
|
||||
|
||||
/// Exposed as the AppleScript `terminals` element on a window.
|
||||
///
|
||||
/// Returns all terminal surfaces across every tab in this window.
|
||||
@objc(terminals)
|
||||
var terminals: [ScriptTerminal] {
|
||||
controllers
|
||||
.flatMap { $0.surfaceTree.root?.leaves() ?? [] }
|
||||
.map(ScriptTerminal.init)
|
||||
}
|
||||
|
||||
/// Enables unique-ID lookup for `terminals` references on a window.
|
||||
@objc(valueInTerminalsWithUniqueID:)
|
||||
func valueInTerminals(uniqueID: String) -> ScriptTerminal? {
|
||||
controllers
|
||||
.flatMap { $0.surfaceTree.root?.leaves() ?? [] }
|
||||
.first(where: { $0.id.uuidString == uniqueID })
|
||||
.map(ScriptTerminal.init)
|
||||
}
|
||||
|
||||
/// AppleScript tab indexes are 1-based, so we add one to Swift's 0-based
|
||||
/// array index.
|
||||
func tabIndex(for controller: BaseTerminalController) -> Int? {
|
||||
|
||||
Reference in New Issue
Block a user