Documentation
¶
Overview ¶
Package termfmt writes text for a terminal: whether to color it, the styles and links, and the width of what it prints. Width is measured on plain text; styles are applied after, so no escape reaches a measure.
Index ¶
- Constants
- func Cells(s string) int
- func Clean(s string) string
- func Cut(s string, w int) string
- func Fit(s string, w int) string
- func FitRight(s string, w int) string
- func Joiner(r rune) bool
- func OneLine(s string, max int) string
- func Plain(s string) string
- func Prefix(s string, w int) string
- func Suffix(s string, w int) string
- func UseWidths(c *runewidth.Condition) (restore func())
- func Wrap(s string, first, rest int) []string
- type Cell
- type Column
- type Mode
- type Term
- func (t Term) Bold(s string) string
- func (t Term) Columns(width, gap int, cols []Column, rows [][]Cell) []string
- func (t Term) Cyan(s string) string
- func (t Term) Dim(s string) string
- func (t Term) Green(s string) string
- func (t Term) Link(url, text string) string
- func (t Term) Red(s string) string
- func (t Term) Reverse(s string) string
- func (t Term) Yellow(s string) string
Constants ¶
const Ellipsis = "…"
Variables ¶
This section is empty.
Functions ¶
func Clean ¶
Clean keeps text to what a terminal prints in place. Control characters become spaces. Bidi controls, line and paragraph separators and invisible format characters, which a title could use to reorder or fake the line, are removed; the zero-width joiner and non-joiner stay, as emoji and scripts such as Persian need them.
func OneLine ¶
OneLine makes text from an agent or a CI fit one line of a row or a notification: control characters become spaces, bidi and zero-width characters go, whitespace collapses, and it keeps at most max runes.
Types ¶
type Column ¶
Column lays out one column: Right aligns it to the right, Max caps its width, and the Flex column takes what the others leave of the width.
type Mode ¶
type Mode int
Mode is the --color choice.
type Term ¶
Term is how to write to one output: TTY lays it out for a person, Color styles it, Width is its columns.
func Detect ¶
Detect decides for w: a terminal gets the layout and color; GH_FORCE_TTY and --color always force both; NO_COLOR, TERM=dumb and CLICOLOR=0 take the color away and CLICOLOR_FORCE gives it back, never the layout, unless NO_COLOR is set; mode overrides the color.
func (Term) Columns ¶
Columns lays rows out gap spaces apart within width cells: each column as wide as its widest value, the flexible one cut to the room left. Cells are measured and cut plain, then styled.
func (Term) Link ¶
Link makes text an OSC 8 hyperlink to url; a terminal that does not know it prints the text.