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
|
@ObservedObject var surfaceView: SurfaceView
|
||||||
var isSplit: Bool = false
|
var isSplit: Bool = false
|
||||||
|
|
||||||
|
// Maintain whether our view has focus or not
|
||||||
|
@FocusState private var inspectorFocus: Bool
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
SplitView(.vertical, left: {
|
let center = NotificationCenter.default
|
||||||
SurfaceWrapper(surfaceView: surfaceView, isSplit: isSplit)
|
let pubInspector = center.publisher(for: Notification.didControlInspector, object: surfaceView)
|
||||||
}, right: {
|
|
||||||
InspectorViewRepresentable(surfaceView: surfaceView)
|
ZStack {
|
||||||
.focusedValue(\.ghosttySurfaceTitle, surfaceView.title)
|
if (!surfaceView.inspectorVisible) {
|
||||||
.focusedValue(\.ghosttySurfaceView, surfaceView)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +252,9 @@ extension Ghostty {
|
|||||||
return ghostty_surface_inspector(surface)
|
return ghostty_surface_inspector(surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// True if the inspector should be visible
|
||||||
|
@Published var inspectorVisible: Bool = false
|
||||||
|
|
||||||
private(set) var surface: ghostty_surface_t?
|
private(set) var surface: ghostty_surface_t?
|
||||||
var error: Error? = nil
|
var error: Error? = nil
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user