render

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 20 Imported by: ? 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

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

Index

Constants

View Source
const ChartLeadIn = 0.06

Recency of the oldest stretch, just off none, so it is still drawn

View Source
const MaxDiffLines = 6000

Lines beyond which a diff is summarized instead of computed

View Source
const ScrollbarWidth = 40

Width a view needs before it spends its last two columns on a scrollbar, a space and the bar

View Source
const TableHead = 2

Rows a table with column titles 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 Beside

func Beside(boxes [][]string, width int) []string

Boxes side by side at the right of rows of the width, one blank column after each, a box shorter than the tallest padded with blank rows and a row narrower than the widest of its box padded with blanks, so the box after it stands straight

func Bytes

func Bytes(n int64) string

Byte count in the largest unit that fits, as every screen says a size: 512 bytes, 1.5 KB, 5 MB

func ChartInk

func ChartInk(recency float64) float64

Ink of a stretch of the recency, from quiet for the oldest to bright for the newest along an eased gradient

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 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 Fit

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

Pads or cuts a string to exactly width columns, measuring a string that fits once

func Good

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

Text in the alive color

func Group

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

Heading of a group of rows in a list, in capitals

func Head(cols []Column) int

Rows the table of these columns spends above its first row, none when no column has a title

func Heading

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

Section heading in bold text

func Lay

func Lay(rows, stack []string, corner Corner, width int) []string

Rows of the width with the stack laid over the corner, the stack cut to the rows there are; the rows given are left as they are

func Money

func Money(f float64) string

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

func Natural

func Natural(cols []Column, rows [][]string) []int

Width every column takes before it is fitted to a table, over the rows: the widest of its title and its cells, kept to its Max

func On

func On(at time.Time) string

When something happened as a sentence says it after a verb, in the person's own zone: at the time for today, on the day for this year, else on the day and the year; empty for no time

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 PaintTimeline

func PaintTimeline(rows [][]ChartRun, colors []color.Color, t theme.Theme, selected int) []string

The rows of a chart painted in the theme: each series in its color, faded toward the background the older its stretch is, the label of the row selected bright, the axis and the counts between series quiet

func Percent

func Percent(f float64) string

Share as a whole percentage

func Relative

func Relative(at time.Time) string

A time to come or gone, in words: now, in 5 minutes, 3 hours ago, or the day and time past a day either way; empty for no time

func ScrollCap

func ScrollCap(chord, arrow string, t theme.Theme) (glyph, label string)

Cap of a paging chord, the theme symbol of its key or an arrow with the chord spelled beside it

func Settled

func Settled(text string) int

Offset in the text where the block that later text can still change starts, so everything before it may be printed as it stands: the start of the last paragraph or heading after a blank line, outside fenced code and raw HTML; 0 while no block is closed yet

func ShareBar

func ShareBar(n, top int64, width int, t theme.Theme) string

Bar of the count's share of the top count in cells of the full width, at least one cell for a count above none

func Spark

func Spark(counts []int64, t theme.Theme) string

The counts as one row of bars of eight heights, the highest count the tallest and none blank

func Spinner

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

Spinner frame for a tick from the theme frames

func Spread

func Spread(cols []Column, natural []int, width int) (xs, widths []int)

Left edge and width of every column at the width, from the widths Natural or Widest gave them, zero for columns dropped from the right to fit

func Stretches

func Stretches(moments []Moment, series, rows int, location *time.Location) ([]Stretch, Grain)

The stretches the moments fall in, oldest first, at the finest grain whose stretches fit the rows, a month of days whatever the rows: stretches holding nothing are left out, and so are moments of no time

func StyleConfig

func StyleConfig(t theme.Theme) ansi.StyleConfig

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

func Table

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

Renders the table with no row in hand, for rows only read such as a report

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 TableResting

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

Renders the table of a list that does not have the keys: the row in hand only marked, its cursor dim and its text bold on no lit background

func Timeline

func Timeline(stretches []Stretch, width int, glyphs ChartGlyphs) [][]ChartRun

Rows of a chart of the stretches at the width, one a stretch and under them the trail of what happened in all: each the label of its stretch, the axis, a bar of each series as long as its share of the busiest stretch and never none for a series the stretch holds, the count of each series it holds, now beside the newest stretch and peak beside the busiest. A width too small for notes leaves them out

func Tokens

func Tokens(n int) string

Token count with a k or M suffix past a thousand

func ToolGlyph

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

Glyph of a tool icon a tool registers, such as "read" or "shell", the plain tool glyph for an unknown icon

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 Unmarked

func Unmarked(markdown string) string

The text of markdown with its marks taken out, the words and the lines kept. Emphasis that touches emphasis is taken out on a second pass, as one pass leaves the second of two marks that share the space between them

func Warm

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

Text in the accent color

func When

func When(at time.Time) string

When something happened, in the person's own zone: the time for today, the day for this year, else the day and the year; empty for no time

func Widest

func Widest(cols []Column, cells [][]int) []int

Width every column takes before it is fitted to a table, from the widths of the cells of its rows measured beforehand, row by row: the widest of its title and its cells, kept to its Max. A long table measures each cell once and lays its columns out again from those

func Widths

func Widths(cells []string) []int

Width of every cell

func Wrap

func Wrap(s string, width int) string

Wraps a string at width, breaking long words

Types

type ChartGlyphs

type ChartGlyphs struct {
	// Cell of a bar, the axis, and a dot and a star of the trail
	Fill, Axis, Dot, Star string
	// Notes beside the newest stretch and the busiest
	Now, Peak string
}

Marks a chart is drawn with

func ChartGlyphsOf

func ChartGlyphsOf(t theme.Theme) ChartGlyphs

Marks of a chart in the theme: its bar fill and separator, with ASCII marks where the theme draws in ASCII alone

type ChartPart

type ChartPart int

What a run of a row of a chart draws

const (
	// Label of a stretch
	PartLabel ChartPart = iota
	// The axis between the labels and the bars
	PartAxis
	// Bar of one series
	PartBar
	// Count of one series, or the plus between two
	PartCount
	// Now beside the newest stretch, peak beside the busiest
	PartNote
	// Trail of what happened in all, under the bars
	PartTrail
	// Cells left blank
	PartGap
)

type ChartRun

type ChartRun struct {
	Text string
	Part ChartPart
	// Series it draws or counts, -1 for none
	Series int
	// How recent its stretch is, from ChartLeadIn for the oldest to 1 for the newest, which a painter fades older stretches by
	Recency float64
}

One run of cells of a row of a chart

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
	// Holds sentences, which are never cut: a list shows the column only at a width that holds every cell of it whole
	Whole bool
}

Column of a table with how its cells align

type Corner

type Corner int

Corner of rows a stack of rows is laid over

const (
	TopLeft Corner = iota
	TopRight
	BottomLeft
	BottomRight
)

type Edit

type Edit struct {
	Col      int
	Text     string
	Cursor   int
	Selected bool
}

Cell of the selected row being typed into in place, its text with the caret at a rune offset, shown selected until the first keystroke

type Grain

type Grain int

How long each stretch of a timeline is

const (
	Daily Grain = iota
	Weekly
	Monthly
	Yearly
)

type Grid

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

Table at column widths laid out beforehand that paints each line on its own, in styles made once: a long table paints only its rows in view, and its columns, measured over every row, hold still as it scrolls

func NewGrid

func NewGrid(cols []Column, widths []int, width int, t theme.Theme) *Grid

Grid of the columns at the widths Columns or Spread laid them out at, in a table width cells wide

func (*Grid) Row

func (g *Grid) Row(cells []string, mark Mark, edit *Edit) string

Line of a row painted as marked, the cell the edit names shown as it is being typed into on the lit row

func (*Grid) Titles

func (g *Grid) Titles() []string

Lines above the rows: the titles and the rule under them, none when no column has a title

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

type Mark

type Mark int

How a row of a table is painted

const (
	// A row like the others
	Plain Mark = iota
	// The row in hand, lit
	Lit
	// The row in hand of a table that does not have the keys, only marked: its cursor dim and its text bold on no lit background
	Held
	// A row of the selection beside the one in hand, tinted
	Tinted
)

type Markdown

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

Markdown renderer cached per theme and width

func NewMarkdown

func NewMarkdown() *Markdown

func (*Markdown) Lines

func (m *Markdown) Lines(src string, width int, t theme.Theme) []string

Lines of markdown at width in the theme, without the blank lines around them

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. The renderer of each width is kept for the look of the theme, so a style handed in again under its own name with other colors draws in them

type Moment

type Moment struct {
	At     time.Time
	Series int
	Index  int
}

A thing that happened, as a timeline draws it: when, the series it counts in, and the index its owner knows it by

type Op

type Op int

Kind of one diff line

const (
	Same Op = iota
	Added
	Removed
)

type ScrollHit

type ScrollHit int

What a click on a scrollbar asks for

const (
	// Nothing, the click missing the scrollbar or nothing scrolling
	ScrollNone ScrollHit = iota
	// A page toward the start, from the top cap
	ScrollPageUp
	// A page toward the end, from the bottom cap
	ScrollPageDown
	// The place on the track under the click
	ScrollJump
)

type Scrollbar

type Scrollbar struct {
	// Rows tall, lines of content in all, the first line in view and the lines in view
	Height, Total, Offset, Visible int
	// Lines that start a turn, ticked along the track, and lines holding a search match
	Marks, Hits []int
	// Chords that page up and down, shown on the caps
	Up, Down string
}

Scrollbar beside content that scrolls: a column of one cell per row, its caps naming the paging keys, its track a timeline of turns and matches. Pages, lists, forms, the detail of a list, the palette and the transcript of a window all draw this one, in the last column

func (Scrollbar) Column

func (s Scrollbar) Column(t theme.Theme) []string

Cells of the scrollbar from the top, one per row, blank while nothing scrolls

func (Scrollbar) DragTo

func (s Scrollbar) DragTo(y, held int) int

Offset that puts the held row of the thumb under row y of the track

func (Scrollbar) Grab

func (s Scrollbar) Grab(y int) int

Row of the thumb a press on row y took hold of, its middle for a press on the track beside it

func (Scrollbar) Hit

func (s Scrollbar) Hit(y int) (ScrollHit, int)

Meaning of a click on row y of the scrollbar, and for a jump the first line to show

func (Scrollbar) OnTrack

func (s Scrollbar) OnTrack(y int) bool

Reports whether row y lies on the track between the caps while the content scrolls

func (Scrollbar) Same

func (s Scrollbar) Same(o Scrollbar) bool

Reports whether two scrollbars draw the same, their marks and hits included

func (Scrollbar) Scrolls

func (s Scrollbar) Scrolls() bool

Reports whether the content runs past the rows in view

type Scrolled

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

Rows of a body laid beside a scrollbar as last composed: the scrollbar's column drawn again only once the scrollbar changed, and each row composed again only once its text, its cell of the scrollbar or its label changed, so a view that only moved a spinner composes one row again

func (*Scrolled) Lay

func (b *Scrolled) Lay(bar Scrollbar, body []string, w int, t theme.Theme) []string

Body rows fitted to two columns short of w with the scrollbar in the last column, a chord without a symbol set beside its cap, one row for each row of the scrollbar

type Stream

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

Markdown of a text that grows at its end, such as a reply as it streams in. Each run of blocks that no later text can change is rendered once and kept; only the block still open after them is rendered again as the text grows, so a long reply costs the same per word as a short one. The lines read as the whole text rendered at once does

func (*Stream) Lines

func (s *Stream) Lines(m *Markdown, text string, width int, t theme.Theme) []string

Lines of the text at width in the theme, rendering again only the block still open once the text is the one asked for before with more after it; any other text, width or theme starts over

func (*Stream) Reset

func (s *Stream) Reset()

Forgets what was rendered, as for a text that went away with the session that wrote it

type Stretch

type Stretch struct {
	// Its first moment, and the first of the stretch after it
	Start, End time.Time
	Label      string
	// Moments of each series in it, and the moments themselves, oldest first
	Counts  []int
	Moments []Moment
}

A stretch of a timeline and what happened in it

func (Stretch) Total

func (s Stretch) Total() int

Moments the stretch holds of every series

Jump to

Keyboard shortcuts

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