mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: terminal inspector control
This commit is contained in:
@ -10,14 +10,60 @@ extension Ghostty {
|
||||
@ObservedObject var surfaceView: SurfaceView
|
||||
var isSplit: Bool = false
|
||||
|
||||
// Maintain whether our view has focus or not
|
||||
@FocusState private var inspectorFocus: Bool
|
||||
|
||||
var body: some View {
|
||||
SplitView(.vertical, left: {
|
||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
||||
}, right: {
|
||||
InspectorViewRepresentable(surfaceView: surfaceView)
|
||||
.focusedValue(\.ghosttySurfaceTitle, surfaceView.title)
|
||||
.focusedValue(\.ghosttySurfaceView, surfaceView)
|
||||
})
|
||||
let center = NotificationCenter.default
|
||||
let pubInspector = center.publisher(for: Notification.didControlInspector, object: surfaceView)
|
||||
|
||||
ZStack {
|
||||
if (!surfaceView.inspectorVisible) {
|
||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
||||
} else {
|
||||
SplitView(.vertical, left: {
|
||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
||||
}, right: {
|
||||
InspectorViewRepresentable(surfaceView: surfaceView)
|
||||
.focused($inspectorFocus)
|
||||
.focusedValue(\.ghosttySurfaceTitle, surfaceView.title)
|
||||
.focusedValue(\.ghosttySurfaceView, surfaceView)
|
||||
})
|
||||
}
|
||||
}
|
||||
.onReceive(pubInspector) { onControlInspector($0) }
|
||||
}
|
||||
|
||||
private func onControlInspector(_ notification: SwiftUI.Notification) {
|
||||
// Determine our mode
|
||||
guard let modeAny = notification.userInfo?["mode"] else { return }
|
||||
guard let mode = modeAny as? ghostty_inspector_mode_e else { return }
|
||||
|
||||
switch (mode) {
|
||||
case GHOSTTY_INSPECTOR_TOGGLE:
|
||||
surfaceView.inspectorVisible = !surfaceView.inspectorVisible
|
||||
|
||||
case GHOSTTY_INSPECTOR_SHOW:
|
||||
surfaceView.inspectorVisible = true
|
||||
|
||||
case GHOSTTY_INSPECTOR_HIDE:
|
||||
surfaceView.inspectorVisible = false
|
||||
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
// When we show the inspector, we want to focus on the inspector.
|
||||
// When we hide the inspector, we want to move focus back to the surface.
|
||||
if (surfaceView.inspectorVisible) {
|
||||
// We need to delay this until SwiftUI shows the inspector.
|
||||
DispatchQueue.main.async {
|
||||
_ = surfaceView.resignFirstResponder()
|
||||
inspectorFocus = true
|
||||
}
|
||||
} else {
|
||||
Ghostty.moveFocus(to: surfaceView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ extension Ghostty {
|
||||
// True if this surface is part of a split view. This is important to know so
|
||||
// we know whether to dim the surface out of focus.
|
||||
var isSplit: Bool = false
|
||||
|
||||
|
||||
// Maintain whether our view has focus or not
|
||||
@FocusState private var surfaceFocus: Bool
|
||||
|
||||
@ -252,6 +252,9 @@ extension Ghostty {
|
||||
return ghostty_surface_inspector(surface)
|
||||
}
|
||||
|
||||
// True if the inspector should be visible
|
||||
@Published var inspectorVisible: Bool = false
|
||||
|
||||
private(set) var surface: ghostty_surface_t?
|
||||
var error: Error? = nil
|
||||
|
||||
|
Reference in New Issue
Block a user