mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-18 21:40:29 +00:00
macos: show URL on OSC8 hover
This commit is contained in:
@@ -93,7 +93,8 @@ extension Ghostty {
|
||||
set_cell_size_cb: { userdata, width, height in App.setCellSize(userdata, width: width, height: height) },
|
||||
show_desktop_notification_cb: { userdata, title, body in
|
||||
App.showUserNotification(userdata, title: title, body: body) },
|
||||
update_renderer_health_cb: { userdata, health in App.updateRendererHealth(userdata, health: health) }
|
||||
update_renderer_health_cb: { userdata, health in App.updateRendererHealth(userdata, health: health) },
|
||||
mouse_over_link_cb: { userdata, ptr, len in App.mouseOverLink(userdata, uri: ptr, len: len) }
|
||||
)
|
||||
|
||||
// Create the ghostty app.
|
||||
@@ -523,6 +524,17 @@ extension Ghostty {
|
||||
let backingSize = NSSize(width: Double(width), height: Double(height))
|
||||
surfaceView.cellSize = surfaceView.convertFromBacking(backingSize)
|
||||
}
|
||||
|
||||
static func mouseOverLink(_ userdata: UnsafeMutableRawPointer?, uri: UnsafePointer<CChar>?, len: Int) {
|
||||
let surfaceView = self.surfaceUserdata(from: userdata)
|
||||
guard len > 0 else {
|
||||
surfaceView.hoverUrl = nil
|
||||
return
|
||||
}
|
||||
|
||||
let buffer = Data(bytes: uri!, count: len)
|
||||
surfaceView.hoverUrl = String(data: buffer, encoding: .utf8)
|
||||
}
|
||||
|
||||
static func showUserNotification(_ userdata: UnsafeMutableRawPointer?, title: UnsafePointer<CChar>?, body: UnsafePointer<CChar>?) {
|
||||
let surfaceView = self.surfaceUserdata(from: userdata)
|
||||
|
||||
@@ -147,13 +147,13 @@ extension Ghostty {
|
||||
|
||||
// If we have a URL from hovering a link, we show that.
|
||||
// TODO
|
||||
if (false) {
|
||||
if let url = surfaceView.hoverUrl {
|
||||
let padding: CGFloat = 3
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
Spacer()
|
||||
|
||||
Text(verbatim: "http://example.com")
|
||||
Text(verbatim: url)
|
||||
.padding(.init(top: padding, leading: padding, bottom: padding, trailing: padding))
|
||||
.background(.background)
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ extension Ghostty {
|
||||
|
||||
// Any error while initializing the surface.
|
||||
@Published var error: Error? = nil
|
||||
|
||||
// The hovered URL string
|
||||
@Published var hoverUrl: String? = nil
|
||||
|
||||
// An initial size to request for a window. This will only affect
|
||||
// then the view is moved to a new window.
|
||||
|
||||
Reference in New Issue
Block a user