pretty

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package pretty draws a command's result in the pretty format, for a person (docs/designs/cli-pretty.md): a view built from the result's shape by the conventions, adjusted by its fields' pretty tags, then drawn for a terminal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorJSON added in v0.18.0

func ColorJSON(b []byte, styles cliui.TerminalStyles, tones Tones) []byte

ColorJSON is b, JSON lines as the CLI writes them (each a compact document), colored by ColorYAML's rules: every key bright blue, null and punctuation faint, a URL as a link, a value with a tone in its hue. Only escape codes are added; without styles, b as it is.

func ColorYAML added in v0.18.0

func ColorYAML(b []byte, styles cliui.TerminalStyles, tones Tones) []byte

ColorYAML is b, YAML as yaml.v3 writes it, colored by cli-pretty.md's rules (docs/designs/cli-pretty.md#color): weight for structure, hue for meaning. Every key is bright blue, siblings alike, the indentation showing what opens a map or a list; null and punctuation faint; a URL as a link; a value with a tone in its hue; any other value plain. Only escape codes are added: removed, they leave b. Without styles (not a terminal, NO_COLOR), b as it is.

func Render

func Render(w io.Writer, v any, width int) error

Render writes v, a command's result, in the pretty format, for a terminal of width (0: not a terminal, so nothing is cut). Colors follow w: on a terminal only, not with NO_COLOR.

func RenderStyled added in v0.18.0

func RenderStyled(w io.Writer, v any, width int, styles cliui.TerminalStyles) error

RenderStyled is Render in styles, the terminal's it's bound for: for a view written into a buffer first, to be placed (an error's details, under its headline), which isn't a terminal itself.

Types

type Object added in v0.18.0

type Object struct {
	Keys   []string
	Values map[string]any
}

Object is an object read from JSON or YAML with its keys in order (an error's details, say), laid out as a struct is, in that order. A map is too, its keys sorted, since it keeps no order.

type Tones added in v0.18.0

type Tones map[string]string

Tones are the values ColorYAML and ColorJSON give a tone, by their key's path, dot-joined from the top: {"error.code": "bad"}. As a pretty view's tone hint, "good", "warn" or "bad".

Jump to

Keyboard shortcuts

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