termoutput

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 11 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

Package termoutput prints command results: tables, JSON, YAML, ASCII graphs, human sizes, and shell-split command lines.

Tables use ASCII borders only, so output is byte-identical on Linux, macOS, and legacy Windows consoles. JSON and YAML marshal with stable key order for golden tests and pipes.

Index

Constants

View Source
const (
	FormatTable = "table"
	FormatJSON  = "json"
	FormatYAML  = "yaml"
)

Formats for Render and the --output flag.

Variables

This section is empty.

Functions

func Bytes

func Bytes(n uint64) string

Bytes renders a byte count for humans, e.g. "1.5 kB".

func Graph

func Graph(values []float64) string

Graph renders values as a plain-ASCII point chart with a labeled axis: pure ASCII, no color codes, safe on every console including raster fonts. Non-finite values are marked ? and ignored when computing the axis.

func IBytes

func IBytes(n uint64) string

IBytes renders a byte count in binary units, e.g. "1.0 MiB".

func JSON

func JSON(w io.Writer, v any) error

JSON writes indented JSON plus a trailing newline. Map keys marshal in sorted order, so output is stable across runs.

func Render

func Render(w io.Writer, format string, v any) error

Render writes v in the named format: table, json, or yaml. Tables need a header plus string rows: pass TableValue{Header, Rows}. Anything else returns an error (app validates --output earlier too).

func Split

func Split(s string) ([]string, error)

Split shell-splits a command line, honouring quotes and escapes.

func Table

func Table(w io.Writer, header []string, rows [][]string) error

Table writes a bordered table (StyleBordered default) with a header row.

func TableStyle

func TableStyle(w io.Writer, tv TableValue, s termtable.Style) error

TableStyle renders with an explicit termtable style: StyleBordered (bordered, the default look) or StyleBorderless (borderless, most script-friendly).

func TableStyleWith

func TableStyleWith(w io.Writer, tv TableValue, s termtable.Style, scheme termstyle.Scheme) error

TableStyleWith renders like TableStyle but styles the header through scheme, on any termtable style. Borderless and grid styles both measure visible width, so styled headers stay aligned either way.

func TableWith

func TableWith(w io.Writer, tv TableValue, scheme termstyle.Scheme) error

TableWith renders like Table but styles the header through scheme: uppercased and underlined when enabled, verbatim otherwise so piped output stays script-friendly. termtable measures ANSI-aware, so styled headers stay aligned.

func YAML

func YAML(w io.Writer, v any) (err error)

YAML writes YAML plus a trailing newline with stable key order.

Types

type TableValue

type TableValue struct {
	Header []string
	Rows   [][]string
}

TableValue carries a table for Render.

Directories

Path Synopsis
internal
humanize
Package humanize converts boring ugly numbers to human-friendly strings and back.
Package humanize converts boring ugly numbers to human-friendly strings and back.

Jump to

Keyboard shortcuts

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