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
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 PathDisplayText ¶
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.
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
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
Render renders url and text as plain text in this mode. An unknown mode renders as FallbackURL.