render

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 18 Imported by: 1 module, 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

Text rendering shared by every card, markdown, code, diffs, tables and small formatters tuned to the theme

Index

Constants

View Source
const MaxDiffLines = 6000

Lines beyond which a diff is summarized instead of computed

View Source
const TableHead = 2

Rows the table spends above its first row, the header and the rule under it

Variables

This section is empty.

Functions

func Bad

func Bad(text string, t theme.Theme) string

Text in the alarm color

func Bar

func Bar(fraction float64, width int, t theme.Theme) string

Horizontal bar of width filled to the fraction in ice and dim past the fill

func Bytes

func Bytes(n int64) string

Byte count in the largest unit that keeps it under a thousand

func Code

func Code(src, lang, path string, t theme.Theme) string

Highlights source for the language or file name in the theme, one line per input line

func CodeStyle

func CodeStyle(t theme.Theme) string

Chroma style name that suits the theme

func Columns

func Columns(cols []Column, rows [][]string, width int) (xs, widths []int)

Left edge and width of every column, zero for columns dropped from the right to fit

func Cool

func Cool(text string, t theme.Theme) string

Text in the ice color

func Count

func Count(n int, noun string) string

Count with its noun, pluralized past one

func Dim

func Dim(text string, t theme.Theme) string

Dim text for secondary information

func Divider

func Divider(width int, t theme.Theme) string

Dashed rule of width with the theme info mark at its middle, dashes alone when too narrow for one

func Elapsed

func Elapsed(d time.Duration) string

Duration rounded to a readable unit

func FileLink(path string, line int, t theme.Theme) string

Hyperlink naming a file position and opening the file

func Fit

func Fit(s string, width int, t theme.Theme) string

Pads or cuts a string to exactly width columns

func FormatDiff

func FormatDiff(lines []Line, width int, t theme.Theme) string

Renders already computed diff lines

func Gauge

func Gauge(fraction float64, width int, t theme.Theme) string

Bar in ice that turns to the accent once the fraction passes three quarters

func Good

func Good(text string, t theme.Theme) string

Text in the alive color

func Heading

func Heading(text string, t theme.Theme) string

Section heading in bold text

func Hot

func Hot(text string, t theme.Theme) string

Text in the pulse color

func Hunks

func Hunks(lines []Line, context int) [][]Line

Hunks of changed lines with the context around them, unchanged runs collapsed to a marker

func KV

func KV(key, value string, t theme.Theme) string

Styled key and value pair on one line

func Language

func Language(path string) string

Language a lexer would call the file, empty when none matches

func Lines

func Lines(s string) []string

Lines of a string, an empty string giving none

func Link(text, url string, t theme.Theme) string

Hyperlink text that opens url in terminals that follow OSC 8

func MarkdownText

func MarkdownText(src string, width int, t theme.Theme) string

Renders markdown at width in the theme using the shared cache

func Money

func Money(f float64) string

Dollars with cents, or fractions of a cent for tiny amounts

func Paint

func Paint(st lipgloss.Style, text string) string

Renders text in the style, restarting the style after every reset inside the text so its background runs unbroken

func Percent

func Percent(f float64) string

Share as a whole percentage

func Spinner

func Spinner(tick int, t theme.Theme) string

Spinner frame for a tick from the theme frames

func Stat

func Stat(lines []Line) (added, removed int)

Counts of added and removed lines

func StyleConfig

func StyleConfig(t theme.Theme) ansi.StyleConfig

Glamour style derived from the theme, starting from the dark, light or ASCII set

func Summary

func Summary(s string, width int, t theme.Theme) string

First line of a string cut to width, the theme ellipsis marking lines left out

func Table

func Table(cols []Column, rows [][]string, width int, selected int, t theme.Theme) string

Renders rows under headers at width, cutting cells to their column and marking the selected row

func TableEdit

func TableEdit(cols []Column, rows [][]string, width int, selected int, edit *Edit, t theme.Theme) string

Renders the table with one cell of the selected row shown as it is being typed into

func TableMarked

func TableMarked(cols []Column, rows [][]string, width int, selected int, marked func(int) bool, edit *Edit, t theme.Theme) string

Renders the table with the cursor row lit and every other marked row tinted as part of the selection

func Tail

func Tail(s string, n int) string

Last n lines of a string

func Tokens

func Tokens(n int) string

Token count with a k or M suffix past a thousand

func ToolGlyph

func ToolGlyph(name string, t theme.Theme) string

Glyph that stands for a tool by name

func Truncate

func Truncate(s string, width int, t theme.Theme) string

Cuts a styled string to width, marking the cut with the theme ellipsis

func Warm

func Warm(text string, t theme.Theme) string

Text in the accent color

func Wrap

func Wrap(s string, width int) string

Wraps a string at width, breaking long words

Types

type Column

type Column struct {
	Title string
	// Share of spare width the column takes, zero fitting it to its content
	Flex int
	// Right aligns the cells, for numbers
	Right bool
	// Largest width the column grows to, unlimited when zero
	Max int
}

Column of a table with how its cells align

type Edit

type Edit struct {
	Col      int
	Text     string
	Selected bool
}

Cell of the selected row being typed into in place, its text shown selected until the first keystroke

type Line

type Line struct {
	Op   Op
	Text string
	Old  int
	New  int
}

One line of a diff with the line numbers it held before and after

func Diff

func Diff(before, after string) []Line

Lines changed between two texts, computed with a longest common subsequence over whole lines

type Markdown

type Markdown struct {
	// contains filtered or unexported fields
}

Markdown renderer cached per theme and width

func NewMarkdown

func NewMarkdown() *Markdown

func (*Markdown) Render

func (m *Markdown) Render(src string, width int, t theme.Theme) string

Renders markdown at width in the theme, falling back to the raw text when glamour refuses the input

type Op

type Op int

Kind of one diff line

const (
	Same Op = iota
	Added
	Removed
)

Jump to

Keyboard shortcuts

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