link

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package link finds the URLs in a piece of text.

A terminal that speaks OSC 8 will make a range of cells clickable, and [grid.Cell] carries the target for exactly that. What it cannot do is work out which part of a line is a URL in the first place — that is this package, and it is a surprising amount of care for what looks like one regular expression.

What is not here

Opening one. Which browser, whether the process is sandboxed, whether a URL from tool output should be opened at all — none of that is a terminal library's to decide, and a library that decided would be a framework for one program. The answer is a byte range and a target; what happens on a click is the caller's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	// Start and End are the byte range of the text that was matched, which is what
	// a caller stamps the target onto with [grid.View.Link].
	Start, End int
	// URL is the target. It is not always the matched text: a bare host is given
	// the scheme it was written without.
	URL string
}

Link is one URL found in a piece of text.

func Detect

func Detect(s string) []Link

Detect finds every URL in s, in the order they appear, as byte ranges into s.

func (Link) Text

func (l Link) Text(s string) string

Text is the matched range of s, which is what was actually written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL