mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-21 23:05:20 +00:00
macos: TerminalEntity
This commit is contained in:
67
macos/Sources/Features/App Intents/TerminalEntity.swift
Normal file
67
macos/Sources/Features/App Intents/TerminalEntity.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
import AppKit
|
||||
import AppIntents
|
||||
|
||||
struct TerminalEntity: AppEntity {
|
||||
let id: UUID
|
||||
|
||||
@Property(title: "Title")
|
||||
var title: String
|
||||
|
||||
static var typeDisplayRepresentation: TypeDisplayRepresentation {
|
||||
TypeDisplayRepresentation(name: "Terminal")
|
||||
}
|
||||
|
||||
var displayRepresentation: DisplayRepresentation {
|
||||
DisplayRepresentation(title: "\(title)")
|
||||
}
|
||||
|
||||
static var defaultQuery = TerminalQuery()
|
||||
|
||||
init(_ view: Ghostty.SurfaceView) {
|
||||
self.id = view.uuid
|
||||
self.title = view.title
|
||||
}
|
||||
}
|
||||
|
||||
struct TerminalQuery: EntityStringQuery, EnumerableEntityQuery {
|
||||
@MainActor
|
||||
func entities(for identifiers: [TerminalEntity.ID]) async throws -> [TerminalEntity] {
|
||||
return all.filter {
|
||||
identifiers.contains($0.uuid)
|
||||
}.map {
|
||||
TerminalEntity($0)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func entities(matching string: String) async throws -> [TerminalEntity] {
|
||||
return all.filter {
|
||||
$0.title.localizedCaseInsensitiveContains(string)
|
||||
}.map {
|
||||
TerminalEntity($0)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func allEntities() async throws -> [TerminalEntity] {
|
||||
return all.map { TerminalEntity($0) }
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func suggestedEntities() async throws -> [TerminalEntity] {
|
||||
return try await allEntities()
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private var all: [Ghostty.SurfaceView] {
|
||||
// Find all of our terminal windows (includes quick terminal)
|
||||
let controllers = NSApp.windows.compactMap {
|
||||
$0.windowController as? BaseTerminalController
|
||||
}
|
||||
|
||||
// Get all our surfaces
|
||||
return controllers.reduce([]) { result, c in
|
||||
result + (c.surfaceTree.root?.leaves() ?? [])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user