mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-01-01 19:22:13 +00:00
macos: show URL on OSC8 hover
This commit is contained in:
@@ -2813,14 +2813,34 @@ pub fn cursorPosCallback(
|
||||
}
|
||||
self.mouse.link_point = pos_vp;
|
||||
|
||||
if (try self.linkAtPos(pos)) |_| {
|
||||
if (try self.linkAtPos(pos)) |link| {
|
||||
self.renderer_state.mouse.point = pos_vp;
|
||||
self.mouse.over_link = true;
|
||||
self.renderer_state.terminal.screen.dirty.hyperlink_hover = true;
|
||||
try self.rt_surface.setMouseShape(.pointer);
|
||||
|
||||
switch (link[0]) {
|
||||
.open => {},
|
||||
|
||||
._open_osc8 => link: {
|
||||
// Show the URL in the status bar
|
||||
const pin = link[1].start();
|
||||
const page = &pin.page.data;
|
||||
const cell = pin.rowAndCell().cell;
|
||||
const link_id = page.lookupHyperlink(cell) orelse {
|
||||
log.warn("failed to find hyperlink for cell", .{});
|
||||
break :link;
|
||||
};
|
||||
const entry = page.hyperlink_set.get(page.memory, link_id);
|
||||
const uri = entry.uri.offset.ptr(page.memory)[0..entry.uri.len];
|
||||
self.rt_surface.mouseOverLink(uri);
|
||||
},
|
||||
}
|
||||
|
||||
try self.queueRender();
|
||||
} else if (over_link) {
|
||||
try self.rt_surface.setMouseShape(self.io.terminal.mouse_shape);
|
||||
self.rt_surface.mouseOverLink(null);
|
||||
try self.queueRender();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +128,11 @@ pub const App = struct {
|
||||
|
||||
/// Called when the health of the renderer changes.
|
||||
update_renderer_health: ?*const fn (SurfaceUD, renderer.Health) void = null,
|
||||
|
||||
/// Called when the mouse goes over a link. The link target is the
|
||||
/// parameter. The link target will be null if the mouse is no longer
|
||||
/// over a link.
|
||||
mouse_over_link: ?*const fn (SurfaceUD, ?[*]const u8, usize) void = null,
|
||||
};
|
||||
|
||||
/// Special values for the goto_tab callback.
|
||||
@@ -1101,6 +1106,19 @@ pub const Surface = struct {
|
||||
|
||||
func(self.userdata, health);
|
||||
}
|
||||
|
||||
pub fn mouseOverLink(self: *const Surface, uri: ?[]const u8) void {
|
||||
const func = self.app.opts.mouse_over_link orelse {
|
||||
log.info("runtime embedder does not support over_link", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
if (uri) |v| {
|
||||
func(self.userdata, v.ptr, v.len);
|
||||
} else {
|
||||
func(self.userdata, null, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// Inspector is the state required for the terminal inspector. A terminal
|
||||
|
||||
Reference in New Issue
Block a user