hyperlink

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package hyperlink provides terminal hyperlink rendering for clog. All configuration is explicit: callers pass a Config (usually derived from the logger's FieldFormats) - the package holds no global state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand added in v0.11.0

func Expand(value, slot string) string

Expand resolves a preset name to its format string for the given slot ("path", "line", or "column"). Returns value unchanged if it is not a known preset name, so full format strings pass through unmodified.

func OSC8

func OSC8(url, text string) string

OSC8 wraps text in raw OSC 8 escape sequences unconditionally.

func PathDisplayText

func PathDisplayText(path string, line, column int) string

PathDisplayText returns the display string for a path hyperlink.

Types

type Config added in v0.11.0

type Config struct {
	// Enabled controls whether hyperlinks are rendered at all. When false,
	// hyperlink helpers return plain text without OSC 8 sequences.
	Enabled bool

	// Fallback selects how a link renders where OSC 8 sequences cannot be
	// emitted. The zero value is [FallbackURL]. It has no effect when Enabled
	// is false, which suppresses links outright.
	Fallback Fallback

	// ColumnFormat is the URL format for file+line+column hyperlinks.
	// Falls back to LineFormat when empty.
	ColumnFormat string
	// DirFormat is the URL format for directory hyperlinks.
	// Falls back to PathFormat when empty.
	DirFormat string
	// FileFormat is the URL format for file-only hyperlinks (no line
	// number). Falls back to PathFormat when empty.
	FileFormat string
	// LineFormat is the URL format for file+line hyperlinks.
	// Falls back to "file://{path}" when empty.
	LineFormat string
	// PathFormat is the generic fallback URL format for any path.
	// Falls back to "file://{path}" when empty.
	PathFormat string
}

Config holds resolved hyperlink rendering configuration. The format strings use {path}, {line}, and {column} (or {col}) as placeholders; an empty string means the documented fallback.

func DefaultConfig added in v0.11.0

func DefaultConfig() Config

DefaultConfig returns the default hyperlink configuration: enabled, with all format slots empty (plain file:// URLs) and FallbackURL where OSC 8 is unavailable.

func Preset added in v0.11.0

func Preset(name string) (Config, error)

Preset returns the Config for a named editor preset. Known presets: cursor, kitty, macvim, subl, textmate, vscode, vscode-insiders, vscodium.

func (Config) ResolvePathURL added in v0.11.0

func (c Config) ResolvePathURL(path string, line, column int) string

ResolvePathURL builds the full hyperlink URL for a file path using the given configuration.

type Fallback added in v0.17.1

type Fallback int

Fallback selects how a hyperlink renders where OSC 8 sequences cannot be emitted - piped output, `NO_COLOR`, or github.com/gechr/clog.ColorNever. It applies to links whose target is independent of their label (OSC8 via a logger's Hyperlink, Link, Links, URL and URLs fields). Path fields are exempt: their label already carries the path, so they render it alone.

const (
	// FallbackURL renders the URL alone, dropping the label. It is the
	// default because a label usually abbreviates its URL, so the URL is what
	// a piped log line needs to stay actionable.
	FallbackURL Fallback = iota // url
	// FallbackExpanded renders `label (url)`.
	FallbackExpanded // expanded
	// FallbackMarkdown renders `[label](url)`.
	FallbackMarkdown // markdown
	// FallbackText renders the label alone, dropping the URL.
	FallbackText // text
)

func ParseFallback added in v0.17.1

func ParseFallback(name string) (Fallback, error)

ParseFallback resolves a fallback mode by name: "url", "expanded", "markdown" or "text". Matching ignores case and surrounding space.

func (Fallback) Render added in v0.17.1

func (f Fallback) Render(url, text string) string

Render renders url and text as plain text in this mode. An unknown mode renders as FallbackURL.

func (Fallback) String added in v0.17.1

func (i Fallback) String() string

Jump to

Keyboard shortcuts

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