diff options
Diffstat (limited to 'core/term/terminal.zig')
| -rw-r--r-- | core/term/terminal.zig | 30 |
1 files changed, 30 insertions, 0 deletions
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, |
