neovim/test/functional/terminal
Gregory Anders 6ea6b3fee2
feat(ui): add support for OSC 8 hyperlinks (#27109)
Extmarks can contain URLs which can then be drawn in any supporting UI.
In the TUI, for example, URLs are "drawn" by emitting the OSC 8 control
sequence to the TTY. On terminals which support the OSC 8 sequence this
will create clickable hyperlinks.

URLs are treated as inline highlights in the decoration subsystem, so
are included in the `DecorSignHighlight` structure. However, unlike
other inline highlights they use allocated memory which must be freed,
so they set the `ext` flag in `DecorInline` so that their lifetimes are
managed along with other allocated memory like virtual text.

The decoration subsystem then adds the URLs as a new highlight
attribute. The highlight subsystem maintains a set of unique URLs to
avoid duplicating allocations for the same string. To attach a URL to an
existing highlight attribute we call `hl_add_url` which finds the URL in
the set (allocating and adding it if it does not exist) and sets the
`url` highlight attribute to the index of the URL in the set (using an
index helps keep the size of the `HlAttrs` struct small).

This has the potential to lead to an increase in highlight attributes
if a URL is used over a range that contains many different highlight
attributes, because now each existing attribute must be combined with
the URL. In practice, however, URLs typically span a range containing a
single highlight (e.g. link text in Markdown), so this is likely just a
pathological edge case.

When a new highlight attribute is defined with a URL it is copied to all
attached UIs with the `hl_attr_define` UI event. The TUI manages its own
set of URLs (just like the highlight subsystem) to minimize allocations.
The TUI keeps track of which URL is "active" for the cell it is
printing. If no URL is active and a cell containing a URL is printed,
the opening OSC 8 sequence is emitted and that URL becomes the actively
tracked URL. If the cursor is moved while in the middle of a URL span,
we emit the terminating OSC sequence to prevent the hyperlink from
spanning multiple lines.

This does not support nested hyperlinks, but that is a rare (and,
frankly, bizarre) use case. If a valid use case for nested hyperlinks
ever presents itself we can address that issue then.
2024-01-24 16:36:25 -06:00
..
altscreen_spec.lua test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00
api_spec.lua refactor: format test/* 2024-01-03 02:09:29 +01:00
buffer_spec.lua test: use integers for API Buffer/Window/Tabpage EXT types 2024-01-16 19:11:49 +00:00
channel_spec.lua test: big cleanup followup 2024-01-17 10:10:17 +00:00
cursor_spec.lua test: normalise nvim bridge functions 2024-01-12 17:53:27 +00:00
edit_spec.lua test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00
ex_terminal_spec.lua fix(edit): don't go to Terminal mode when stopping Insert mode (#27033) 2024-01-16 10:42:09 +08:00
helpers.lua test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00
highlight_spec.lua test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00
mouse_spec.lua test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00
scrollback_spec.lua test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00
tui_spec.lua feat(ui): add support for OSC 8 hyperlinks (#27109) 2024-01-24 16:36:25 -06:00
window_spec.lua refactor: format test/* 2024-01-03 02:09:29 +01:00
window_split_tab_spec.lua test: rename (meths, funcs) -> (api, fn) 2024-01-12 18:59:14 +00:00