mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
core: helper to get osc8 URI
This commit is contained in:
@ -2626,16 +2626,10 @@ fn processLinks(self: *Surface, pos: apprt.CursorPos) !bool {
|
|||||||
},
|
},
|
||||||
|
|
||||||
._open_osc8 => {
|
._open_osc8 => {
|
||||||
// Note: we probably want to put this into a helper on page.
|
const uri = self.osc8URI(sel.start()) orelse {
|
||||||
const pin = sel.start();
|
log.warn("failed to get URI for OSC8 hyperlink", .{});
|
||||||
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", .{});
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
const link = page.hyperlink_set.get(page.memory, link_id);
|
|
||||||
const uri = link.uri.offset.ptr(page.memory)[0..link.uri.len];
|
|
||||||
try internal_os.open(self.alloc, uri);
|
try internal_os.open(self.alloc, uri);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -2643,6 +2637,17 @@ fn processLinks(self: *Surface, pos: apprt.CursorPos) !bool {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the URI for an OSC8 hyperlink at the given position or null
|
||||||
|
/// if there is no hyperlink.
|
||||||
|
fn osc8URI(self: *Surface, pin: terminal.Pin) ?[]const u8 {
|
||||||
|
_ = self;
|
||||||
|
const page = &pin.page.data;
|
||||||
|
const cell = pin.rowAndCell().cell;
|
||||||
|
const link_id = page.lookupHyperlink(cell) orelse return null;
|
||||||
|
const entry = page.hyperlink_set.get(page.memory, link_id);
|
||||||
|
return entry.uri.offset.ptr(page.memory)[0..entry.uri.len];
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mousePressureCallback(
|
pub fn mousePressureCallback(
|
||||||
self: *Surface,
|
self: *Surface,
|
||||||
stage: input.MousePressureStage,
|
stage: input.MousePressureStage,
|
||||||
@ -2825,14 +2830,10 @@ pub fn cursorPosCallback(
|
|||||||
._open_osc8 => link: {
|
._open_osc8 => link: {
|
||||||
// Show the URL in the status bar
|
// Show the URL in the status bar
|
||||||
const pin = link[1].start();
|
const pin = link[1].start();
|
||||||
const page = &pin.page.data;
|
const uri = self.osc8URI(pin) orelse {
|
||||||
const cell = pin.rowAndCell().cell;
|
log.warn("failed to get URI for OSC8 hyperlink", .{});
|
||||||
const link_id = page.lookupHyperlink(cell) orelse {
|
|
||||||
log.warn("failed to find hyperlink for cell", .{});
|
|
||||||
break :link;
|
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);
|
self.rt_surface.mouseOverLink(uri);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user