render

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 6 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 holds the small text helpers shared by the commands' human output: relative times, aligned tables, the terminal width, colour and plural counts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Age

func Age(d time.Duration) string

Age renders how long something has waited, for a line of text and a JSON value: "10s", "5m", "1h 12m", "2d 3h". It shows the two largest units that are not zero (seconds under a minute, minutes under an hour, hours and minutes under a day, days and hours after), and rounds down. A negative d reads "0s".

func Color

func Color(o Opts, state, text string) string

Color wraps text in an ANSI colour for state, but only on a terminal with colour on: o.TTY, not o.NoColor, and NO_COLOR unset or empty. "online" and "ok" are green, "FAIL" and "fail" red, "warn" yellow; any other state is plain.

func Cut

func Cut(s string, cols int) string

Cut shortens s to at most cols display columns, ending in "…" when it was cut (the ellipsis is within cols). A cols below 1 returns s whole.

func DisplayWidth

func DisplayWidth(s string) int

DisplayWidth is the number of terminal columns s takes: east-asian wide characters and emoji count 2, combining marks and zero-width characters 0, everything else 1.

func Plural

func Plural(n int, noun string) string

Plural renders a count with its noun: "1 message", "3 messages". The plural adds "s".

func RelTime

func RelTime(now, t time.Time) string

RelTime renders t relative to now: "10s ago", "1m ago", "3h ago", "2d ago", and the date (2026-11-19) once t is more than 30 days old. A t at or after now reads "0s ago".

func Table

func Table(cols []string, rows [][]string, width int, truncateLast bool) string

Table lays out a header and rows in columns separated by two spaces. The header is upper-cased. No line has trailing spaces. When truncateLast is set and a line is wider than width, the last column is cut to fit and ends with "…"; widths are display columns (see DisplayWidth) and cuts fall on rune boundaries. A last column that cannot be shown in at least one rune is left whole. The result has no final newline.

func Width

func Width(env func(string) string, isTTY bool) int

Width is the number of columns to lay out for: COLUMNS when it is a positive number and out is a terminal, otherwise 80. env looks up an environment variable.

Types

type Opts

type Opts struct {
	Detail  bool
	NoColor bool
	Width   int  // terminal columns; 0 means 80
	TTY     bool // stdout is a terminal
}

Opts are the output options a command's Text method receives.

Jump to

Keyboard shortcuts

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