render

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Highlight(text, lang string, style *chroma.Style) (string, bool)

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

func Markdown(src string, width int, style ansi.StyleConfig) (string, error)

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

func Matches(text string, spans []tool.Span, style lipgloss.Style) string

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.

func Swatch added in v0.2.0

func Swatch(hex string) string

Swatch draws two rows of the colour hex ("#rrggbb"). The colour is data, not theme, so it is the one style built outside theme.go; the terminal's colour profile downsamples it when there is no truecolor.

Types

type DiffStyles

type DiffStyles struct {
	Insert, Delete, Change, Hunk lipgloss.Style
}

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).

Jump to

Keyboard shortcuts

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