summaryrefslogtreecommitdiff
path: root/core/term
diff options
context:
space:
mode:
Diffstat (limited to 'core/term')
-rw-r--r--core/term/term.zig1
-rw-r--r--core/term/terminal.zig30
2 files changed, 31 insertions, 0 deletions
diff --git a/core/term/term.zig b/core/term/term.zig
index 025f7239..e6250aae 100644
--- a/core/term/term.zig
+++ b/core/term/term.zig
@@ -51,6 +51,7 @@ pub const ops: iface.Ops = .{
.editRows = cast(iface.Ops, "editRows", terminal_.editRows),
.promptCut = cast(iface.Ops, "promptCut", terminal_.promptCutAt),
.echoCell = cast(iface.Ops, "echoCell", terminal_.echoCell),
+ .link = cast(iface.Ops, "link", terminal_.link),
.page = pager.parse,
.filter = terminal_.pagerFilter,
.spanColor = terminal_.spanColor,
diff --git a/core/term/terminal.zig b/core/term/terminal.zig
index 12306957..d31545f5 100644
--- a/core/term/terminal.zig
+++ b/core/term/terminal.zig
@@ -1122,6 +1122,36 @@ pub fn echoCell(state: *const State, x: u16, y: u16) ?Term.EchoCell {
return .{ .cp = ci.cell.codepoint(), .input = ci.cell.semantic_content == .input, .style = ci.cell.style_id };
}
+/// The link (OSC 8) cell `x` of row `row` (from the top of the history)
+/// carries, and the cells its run takes on that row; `cut`: counted in the
+/// row's text, its prompt's own cells cut off (promptCut).
+pub fn link(state: *State, row: i32, x: u16, cut: bool) ?Term.Link {
+ if (row < 0) return null;
+ const pin = state.vt.screens.active.pages.pin(.{ .screen = .{ .x = 0, .y = @intCast(row) } }) orelse return null;
+ const shift: usize = if (!cut or pin.rowAndCell().row.semantic_prompt == .none) 0 else switch (promptCut(pin)) {
+ .keep => 0,
+ .blank => return null,
+ .cut => |n| n,
+ };
+ const cells = pin.cells(.all);
+ const at = @as(usize, x) + shift;
+ if (at >= cells.len) return null;
+ const page = pin.node.page();
+ if (!cells[at].hyperlink) return null;
+ const id = page.lookupHyperlink(&cells[at]) orelse return null;
+ var lo = at;
+ while (lo > shift and sameLink(page, &cells[lo - 1], id)) lo -= 1;
+ var hi = at + 1;
+ while (hi < cells.len and sameLink(page, &cells[hi], id)) hi += 1;
+ const uri = page.hyperlink_set.get(page.memory, id).uri.slice(page.memory);
+ return .{ .uri = uri, .lo = @intCast(lo - shift), .hi = @intCast(hi - shift) };
+}
+
+fn sameLink(page: *const ghostty_vt.page.Page, cell: *const ghostty_vt.page.Cell, id: anytype) bool {
+ if (!cell.hyperlink) return false;
+ return (page.lookupHyperlink(cell) orelse return false) == id;
+}
+
fn promptRow(pin: ghostty_vt.Pin, raw: []const u8) []const u8 {
const cols = switch (promptCut(pin)) {
.keep => return raw,