link

package
v1.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package link decides how a URL the user may need to open by hand is delivered to the terminal: as an OSC 8 hyperlink with a short label, through the clipboard, or as the raw URL. It holds the pure decision logic and the escape sequences; writing to the terminal lives in pkg/ui.

Index

Constants

View Source
const MaxInlineWidth = 80

MaxInlineWidth is the widest URL a bordered dialog may contain. Longer URLs are delivered outside the box so the border never wraps and never ends up in copied text, while short device-code URLs stay with their instructions.

Variables

This section is empty.

Functions

func ClipboardSequence

func ClipboardSequence(text string) string

ClipboardSequence returns the OSC 52 sequence that asks the terminal to put text on the system clipboard. Unlike a native clipboard write it travels through containers and SSH, but the terminal gives no confirmation.

func FitsInline

func FitsInline(url string) bool

FitsInline reports whether a URL is short enough to sit inside a dialog box.

func Hyperlink(url, label string) string

Hyperlink wraps label in an OSC 8 hyperlink to url. Terminals that support OSC 8 show only the label and open url when it is clicked.

func SupportsHyperlinks(env Environment) bool

SupportsHyperlinks reports whether the terminal is known to render OSC 8 hyperlinks. Terminals offer no query for this, so detection is an allowlist of environment variables that identify a terminal. It deliberately errs towards false: a miss only costs the short label, while a false positive would hide the URL behind a label that cannot be clicked.

Types

type Environment

type Environment struct {
	// IsTTY reports whether the stream the link is written to is a terminal.
	IsTTY bool
	// Lookup returns an environment variable, in the manner of os.LookupEnv.
	Lookup func(name string) (string, bool)
}

Environment is what hyperlink detection can see of the terminal.

type Mode

type Mode string

Mode selects how a long URL is delivered. It is configured with `settings.terminal.links` in atmos.yaml or ATMOS_TERMINAL_LINKS.

const (
	// ModeAuto uses an OSC 8 hyperlink when the terminal is known to support
	// one and the raw URL otherwise.
	ModeAuto Mode = "auto"
	// ModeOSC8 always emits an OSC 8 hyperlink with a short label.
	ModeOSC8 Mode = "osc8"
	// ModeClipboard copies the URL to the clipboard.
	ModeClipboard Mode = "clipboard"
	// ModeRaw always prints the full URL as plain text.
	ModeRaw Mode = "raw"
)

func ParseMode

func ParseMode(value string) (Mode, bool)

ParseMode converts a configured value into a Mode. An empty value means ModeAuto. The boolean is false when the value is not a known mode, in which case ModeAuto is returned so a typo never hides a sign-in URL.

func Resolve

func Resolve(mode Mode, env Environment) Mode

Resolve turns a configured mode into the mode to use for this terminal. It never returns ModeAuto. Output that is not a terminal always gets the raw URL, because escape sequences and clipboard writes are wrong for pipes, logs and CI.

Jump to

Keyboard shortcuts

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