Documentation
¶
Overview ¶
Package highlight provides small, terminal-safe syntax highlighting for human-facing previews. It deliberately does not alter source content or participate in scanning, token counts, or selection.
Index ¶
- func ANSI(hex string, mods ...string) string
- func Render(path string, content []byte, options Options) string
- func RenderDocumentLine(doc *Document, line int, options Options) string
- func RenderLine(path, line string, options Options) string
- type ColorProfile
- type Document
- type Line
- type Options
- type Palette
- type Span
- type SyntaxCache
- type SyntaxPalette
- type Theme
- type TokenKind
- type TokenStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ANSI ¶ added in v1.2.0
ANSI builds a truecolor SGR sequence for hex (e.g. "#cba6f7" or "cba6f7") with optional SGR modifiers ("1" for bold, "2" for faint). It returns "" for unparseable input so callers degrade to unstyled text.
func Render ¶
Render highlights complete content. It is intended for a terminal writer; callers must decide whether their output is a TTY before enabling it.
func RenderDocumentLine ¶ added in v1.3.0
RenderDocumentLine renders one parsed line with the supplied palette.
func RenderLine ¶
RenderLine highlights one line. Keeping this operation line-local makes it suitable for the TUI, which can render only the visible preview rows.
Types ¶
type ColorProfile ¶ added in v1.3.0
type ColorProfile uint8
ColorProfile controls semantic ANSI color degradation.
const ( ProfileTrueColor ColorProfile = iota ProfileANSI256 ProfileANSI16 ProfileNone )
type Options ¶
type Options struct {
Enabled bool
Theme Theme
MaxBytes int
Profile ColorProfile
// Palette overrides the built-in Theme palette when non-nil. The TUI
// sets it from the active color preset so preview highlighting follows
// the picker's theme; Theme is kept as the fallback.
Palette *Palette
// Syntax is the semantic palette used by the cached document renderer.
// Palette remains supported for compatibility with existing callers.
Syntax *SyntaxPalette
}
Options controls terminal highlighting.
type Palette ¶ added in v1.2.0
type Palette struct {
Keyword, String, Number, Comment, TypeName string
}
Palette holds the SGR sequences for each token class. The TUI builds one per color preset so preview highlighting matches the picker's theme.
type Span ¶ added in v1.3.0
Span is a half-open semantic range within a line. Offsets are byte offsets.
type SyntaxCache ¶ added in v1.3.0
type SyntaxCache struct {
// contains filtered or unexported fields
}
SyntaxCache stores theme-independent documents by path and content hash. It is intentionally process-local; semantic results are not persisted.
func NewSyntaxCache ¶ added in v1.3.0
func NewSyntaxCache() *SyntaxCache
NewSyntaxCache creates an empty cache with a bounded number of documents.
func NewSyntaxCacheWithCapacity ¶ added in v1.3.0
func NewSyntaxCacheWithCapacity(maxEntries int) *SyntaxCache
NewSyntaxCacheWithCapacity creates a cache holding at most maxEntries documents. A non-positive capacity uses the default of 256.
func (*SyntaxCache) Get ¶ added in v1.3.0
func (c *SyntaxCache) Get(path string, content []byte, options Options) *Document
Get returns a cached document or parses content once for the current hash. Parsing deliberately happens outside the mutex: a large preview must not block another caller from invalidating or reading a different entry.
func (*SyntaxCache) Invalidate ¶ added in v1.3.0
func (c *SyntaxCache) Invalidate(path string)
Invalidate removes one path from the cache.
type SyntaxPalette ¶ added in v1.3.0
type SyntaxPalette map[TokenKind]TokenStyle
SyntaxPalette maps semantic token meanings to appearance styles.
type TokenKind ¶ added in v1.3.0
type TokenKind uint8
TokenKind identifies the meaning of a source span without embedding color or terminal details.
const ( TokenPlain TokenKind = iota TokenComment TokenDocComment TokenKeyword TokenString TokenStringEscape TokenRegex TokenNumber TokenBool TokenNull TokenType TokenFunction TokenVariable TokenConstant TokenProperty TokenBuiltin TokenOperator TokenPunctuation TokenAttribute TokenDecorator TokenTag TokenTagAttribute TokenMarkupHeading TokenMarkupLink TokenShebang TokenDiffAdded TokenDiffRemoved TokenDiffHunk )