Skip to content

Conversation

@slang25
Copy link

@slang25 slang25 commented Jan 11, 2026

Summary

  • Add support for clicking OSC 8 hyperlinks (Cmd/Ctrl+click opens the link)
  • Add getHyperlinkUri API to WASM to retrieve the actual URI for hyperlinked cells
  • Fix link caching to handle multiple hyperlinks on the same line correctly

Problem

OSC 8 hyperlinks (created with escape sequences like \e]8;;http://example.com\e\\Link text\e]8;;\e\\) were visually detected and underlined on hover, but Cmd+clicking them did nothing. Additionally, when multiple hyperlinks existed on the same line, all links would incorrectly open the same URL.

Root Causes

  1. Missing WASM API: The WASM didn't expose a function to retrieve the hyperlink URI. The hyperlink_id field in cells was just a boolean (0 or 1) indicating presence of a hyperlink, not a unique identifier.

  2. Incorrect link caching: The LinkDetector cached links by h${hyperlinkId}, but since all hyperlinks have hyperlink_id=1, all links on a line would share the same cache key, causing only the last discovered link to be returned for any hyperlink cell.

Solution

  1. Added ghostty_terminal_get_hyperlink_uri(row, col) to the WASM API that looks up the actual URI from Ghostty's internal hyperlink storage.

  2. Updated OSC8LinkProvider to use the new WASM API to fetch URIs, with proper coordinate conversion from buffer rows to viewport rows.

  3. Fixed LinkDetector to cache links by position range (r${row}:${startX}-${endX}) instead of hyperlink_id, ensuring each link is cached uniquely.

Test Plan

  • Create OSC 8 hyperlink: printf '\e]8;;http://example.com\e\\Link text\e]8;;\e\\\n'
  • Verify link is underlined on hover
  • Verify Cmd+click opens the URL
  • Create multiple links on one line: printf '\e]8;;http://google.com\e\\Google\e]8;;\e\\ and \e]8;;http://github.com\e\\GitHub\e]8;;\e\\\n'
  • Verify each link opens its respective URL when Cmd+clicked
  • Verify plain text URLs (regex detection) still work

🤖 Generated with Claude Code

Add support for clicking OSC 8 hyperlinks in the terminal. This involves:

1. Add ghostty_terminal_get_hyperlink_uri() to the WASM API to retrieve the
   actual URI for cells marked with hyperlinks. The hyperlink_id field is
   just a boolean indicator; the real URI is stored in Ghostty's internal
   hyperlink set and must be looked up via this new function.

2. Update OSC8LinkProvider to use the new WASM API, with proper coordinate
   conversion from buffer rows to viewport rows (accounting for scrollback).

3. Fix LinkDetector to cache links by position range rather than hyperlink_id,
   since all hyperlinks incorrectly shared the same ID value (1), causing
   multiple links on one line to all open the same URL.

Now Cmd+clicking (Mac) or Ctrl+clicking (Windows/Linux) an OSC 8 hyperlink
correctly opens that specific link's URI.

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
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.

1 participant