Expand description
OSC 8 terminal hyperlinks.
Like crate::term::progress (OSC 9;4), this is an out-of-band terminal
capability that ratatui’s cell buffer cannot carry: a Cell holds one
grapheme + style, with nowhere to attach a link target, and embedding the
escape in a cell’s symbol breaks width accounting. So hyperlinks are emitted
by writing styled spans directly to the terminal, wrapping link runs in the
OSC 8 sequence:
ESC ] 8 ; ; <url> ST <visible text> ESC ] 8 ; ; STwhere ST is the string terminator (ESC \). Terminals that support OSC 8
(Ghostty, iTerm2, WezTerm, Kitty, recent VTE) make the run clickable; others
ignore the unknown OSC and render the text unchanged.
encode is the pure encoder (validated + sanitized, unit-testable with no
I/O). write_line serializes a ratatui Line — colors, common
modifiers, and OSC 8 links — to any Write sink, so a host can push a
transcript line to scrollback with real hyperlinks instead of going through
the cell buffer.
Structs§
- Buffer
Link - A hyperlink run in a rendered buffer: columns
[start_col, end_col)online(0-based within the rendered lines, not screen coordinates) point aturl. Produced by markdown when a[label](url)(or bare URL) survives wrapping; applied withapply_buffer_links. - Hyperlink
Backend - A ratatui
Backendthat wrapsCrosstermBackendand makeshttp(s)URLs in rendered output real OSC 8 hyperlinks. - Link
Policy - Which URL schemes tuika turns into OSC 8 hyperlinks.
Functions§
- apply_
buffer_ links - Embed OSC 8 hyperlinks for each
BufferLinkintobuf. - ctrl_
click_ url - Return the visible HTTP(S) URL under a Ctrl+left-button release.
- ctrl_
click_ url_ with ctrl_click_urlwith an explicitLinkPolicyfor the bare-URL fallback.- encode
encode_withunder the default (LinkPolicy::WEB) policy: wraptextin a link tourlwhenurlis a safehttp(s)URL, else returntext.- encode_
with - Wrap
textin an OSC 8 hyperlink tourlunderpolicy, or returntextunchanged whenurlis not a valid, safe target for that policy. Pure and allocation-only — no I/O. - is_
web_ url - Whether
sis a barehttp(s)://URL with no interior whitespace — the shape a host can hand towrite_lineas a link run. - write_
line - Serialize a ratatui
Linetooutwith SGR styling and OSC 8 links, then reset styling. A span whose visible text is a bare web URL (seeis_web_url) is emitted as a hyperlink to itself; every other span is printed as plain styled text. Does not emit a trailing newline — the caller controls line breaks. - write_
line_ with write_linewith an explicitLinkPolicy, so a host can decide which schemes (e.g.mailto:) become hyperlinks when it pushes a line to scrollback.