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 Matches(text string, spans []tool.Span, style lipgloss.Style) string
- func Result(res tool.Result, kind tool.OutputKind, inputs map[string]string, s Styles) (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 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, 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). 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.