Skip to content

Paint links as OSC 8 hyperlinks - #107

Open
brainkim wants to merge 4 commits into
mainfrom
osc8
Open

brainkim wants to merge 4 commits into
mainfrom
osc8

Conversation

@brainkim

@brainkim brainkim commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

This pull request was generated by Claude Code.

Closes #106.

An a[href] (or area[href]) whose href resolves to an absolute http, https or mailto URL now paints its text as a terminal hyperlink:

ESC ] 8 ; id=<n> ; <url> ESC \  …text…  ESC ] 8 ; ; ESC \

so iTerm2, kitty, WezTerm, Ghostty, foot and Alacritty let the user open it with their own modifier-click or hover, whether or not the page has the mouse. tmux 3.4+ passes the sequence through. Terminal.app has never implemented OSC 8 and ignores the sequence, so a link there looks like any underlined text. The engine still never follows a link itself; a click listener is where an app acts on one.

How it's done:

  • The cell grid gains a link plane holding an id into a per-screen URL table, so ids are stable across frames and a link that wraps or repaints stays one link to the terminal.
  • The frame writer tracks the open link, opens the OSC 8 string when a cell's link differs, and closes it before any cursor move or style reset; a wrapped link reopens on each row with the same id.
  • The diff treats a link change like a style change, so editing only href repaints.
  • The painter resolves the nearest enclosing link per text node. It is not part of the cached paint style, which is shared by every element that resolves to the same values.
  • A fragment, a relative URL, or an anchor without href links nothing; a relative URL resolves against the document URL as a.href does.
  • The document printed into the scrollback on exit keeps its links.
  • file: and ftp: URLs are not linked: a page served from another machine would otherwise open a path on the terminal's own. A URL over 2083 characters or with a control byte is not linked either, and the URL table forgets URLs no cell links to once it passes 1024.

Tests cover the bytes for a link, a link wrapped across lines sharing one id, the three non-links, resolution against the document URL, a href-only change, and the exit print. The input guide describes it.

🤖 Generated with Claude Code

https://claude.ai/code/session_015Bw3yEu4cfkuDkaZ3RSy4D

@brainkim
brainkim marked this pull request as draft September 22, 2026 22:29
@brainkim
brainkim force-pushed the osc8 branch 3 times, most recently from 56c3709 to a2f0c42 Compare September 25, 2026 01:21
The engine cannot follow a link, but the terminal can. A text cell now
carries the id of the link it belongs to, in a table of URLs the
framebuffer keeps for its life, so a link that repaints or wraps stays
one link to the terminal. The frame writer opens the OSC 8 string when a
cell's link differs from the one it has open and closes it before any
cursor move, and the diff repaints a cell whose link alone changed. The
painter takes the URL from the nearest a[href] or area[href] with an
absolute http, https, mailto, file or ftp URL; a fragment, a relative
URL or an anchor without href links nothing. The link joins the cell
style per text node rather than in the paint style, which is shared by
every element resolving to the same values.

Closes #106.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Bw3yEu4cfkuDkaZ3RSy4D
@brainkim
brainkim marked this pull request as ready for review November 12, 2026 18:11
brainkim and others added 3 commits November 12, 2026 14:29
# Conflicts:
#	src/internal/painter.ts
A file: link from a page served from another machine would open a path
on the terminal's own. A URL is also held to 2083 characters and to no
control bytes, and the table of URLs forgets those no cell links to.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit OSC 8 hyperlinks for links

1 participant