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 ¶
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 ¶
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 ¶
FitsInline reports whether a URL is short enough to sit inside a dialog box.
func Hyperlink ¶
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 ¶
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 ¶
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.