Documentation
¶
Overview ¶
Package render colours tool outputs for the terminal. The TUI and the CLI both use it; tools know nothing about colours.
Index ¶
- Constants
- func Diff(res tool.Result, s DiffStyles) string
- func Highlight(text, lang string, style *chroma.Style) (string, bool)
- func Markdown(src string, width int, style ansi.StyleConfig) (string, error)
- func Matches(text string, spans []tool.Span, style lipgloss.Style) string
- func Result(res tool.Result, kind tool.OutputKind, inputs map[string]string, width int, ...) (rendered string, noColor bool)
- func Swatch(hex string) string
- type DiffStyles
- type Styles
Constants ¶
const MaxBytes = 64 << 10
MaxBytes: above this size the output is not coloured. BenchmarkHighlight (Ryzen 7 7700): 64 KB ≈ 35 ms, 256 KB ≈ 127 ms, 1 MB ≈ 446 ms; 64 KB is what fits the 50 ms budget.
Variables ¶
This section is empty.
Functions ¶
func Diff ¶
func Diff(res tool.Result, s DiffStyles) string
Diff colours a DiffView output. Result.Lang tells the format: "diff" (unified: +/-/@@ prefix), "diff-side" (</>/| marker at line start) or empty (by words: Result.Diff operations are painted).
func Highlight ¶
Highlight colours text with lang's lexer using 16 ANSI colours. It returns ok=false when there is no lexer or colouring fails.
func Markdown ¶ added in v1.0.0
Markdown renders src for the terminal with Glamour, wrapped at width (80 when width <= 0). Code blocks use Chroma's 16-colour formatter, like the rest of the output.
func Matches ¶
Matches returns text with the whole matches (Group 0) highlighted. Styles are applied per line so lipgloss does not pad multi-line blocks.
func Result ¶
func Result(res tool.Result, kind tool.OutputKind, inputs map[string]string, width int, s Styles) (rendered string, noColor bool)
Result colours the result according to the tool's output kind. inputs are the run's inputs (Matches highlights over them) and width the columns available (Markdown wraps to it). It returns an empty rendered when it does not apply, and noColor when skipped for size.
Types ¶
type DiffStyles ¶
DiffStyles defines the colours of a diff.
type Styles ¶
type Styles struct {
Chroma *chroma.Style // Highlighted outputs
Match lipgloss.Style // matches in Matches outputs
Diff DiffStyles // DiffView outputs
Markdown *ansi.StyleConfig // Lang "markdown" (Glamour); nil leaves it plain
}
Styles gathers the colouring styles (the TUI takes them from theme.go).