Skip to content

Add hyperlink support

Fixes #21 (closed).

Both OSC 8 links and printed URLs now use the same logic to determine the type of a clicked link based on the pre-existing regexes.

I've also added a terminal_widget_link_clickable function to determine if the file:// link should be clickable or not based on the hostname as described in OSC 8 links feature spec. It now also applies to printed URLs: links that don't have a valid host name are no longer openable via Ctrl+LMB/MMB and and don't have "Open Link" context menu item ("Copy Link" is still there, though).

Here's the a bash script I've used to test various link types:

#!/bin/bash

LINKS=()
URIS=()

LINKS+=("Non-local file link")
URIS+=("file://example.com/etc/passwd")

LINKS+=("Localhost file link")
URIS+=("file://localhost/etc/passwd")

LINKS+=("Hostname file link")
URIS+=("file://$(hostname)/etc/passwd")

LINKS+=("Full HTTP link")
URIS+=("https://example.com")

LINKS+=("Partial HTTP link")
URIS+=("www.example.com")

LINKS+=("Magnet link")
URIS+=("magnet:?xt=urn:btih:b813f485c0e6d17f6877c8d6942b3bdc7c227176&dn=xubuntu-22.04.1-desktop-amd64.iso")

for K in "${!LINKS[@]}"; do
printf 'OSC8 link: \e]8;;%s\e\\%s\e]8;;\e\\, URI: %s\n' "${URIS[$K]}" "${LINKS[$K]}" "${URIS[$K]}"
done
Edited by Ivan Kapelyukhin

Merge request reports