Help us shape the future of Go! Take the 2026 Go Developer Survey

highlight

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ANSI added in v1.2.0

func ANSI(hex string, mods ...string) string

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

func Render(path string, content []byte, options Options) string

Render highlights complete content. It is intended for a terminal writer; callers must decide whether their output is a TTY before enabling it.

func RenderLine

func RenderLine(path, line string, options Options) string

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 Options

type Options struct {
	Enabled  bool
	Theme    Theme
	MaxBytes int
	// 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
}

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 Theme

type Theme string
const (
	ThemeAuto  Theme = "auto"
	ThemeNone  Theme = "none"
	ThemeDark  Theme = "dark"
	ThemeLight Theme = "light"
)

Jump to

Keyboard shortcuts

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