Help us shape the future of Go! Take the 2026 Go Developer Survey

fmtx

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 5 Imported by: 16

README

fmtx: beautiful and simple text interfaces

Documentation

Index

Constants

View Source
const (
	Reset    = "\033[0m"
	Red      = "\033[91m"
	Green    = "\033[92m"
	Yellow   = "\033[93m"
	Blue     = "\033[94m"
	Magenta  = "\033[95m"
	Cyan     = "\033[96m"
	Dim      = "\033[2m"
	Bold     = "\033[1m"
	BgRed    = "\033[41m"
	BgGreen  = "\033[42m"
	BgYellow = "\033[43m"
)

Variables

View Source
var EnableColor = os.Getenv("NO_COLOR") == ""
View Source
var SparkBlocks = []rune{' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}

SparkBlocks are Unicode block characters for drawing sparklines, from empty (space) to full block. Levels 0..8.

Functions

func BgGreenS

func BgGreenS(s string) string

func BgRedS

func BgRedS(s string) string

func BlueS

func BlueS(s string) string

func BoldS

func BoldS(s string) string

func ColorizeDist added in v0.1.9

func ColorizeDist[T cmp.Ordered](s string, v T, points []T, colors []string) string

ColorizeDist colorizes s based on which interval v falls into. points must be sorted ascending; colors must have len(points)+1 elements. colors[0]: v < points[0] colors[i]: points[i-1] <= v < points[i] colors[len(points)]: v >= points[len(points)-1]

func ColorizeMinMax added in v0.1.2

func ColorizeMinMax[T comparable](s string, v, min, max T, minC, maxC string) string

func DimS

func DimS(s string) string

func GreenS

func GreenS(s string) string

func HeaderTo added in v0.1.8

func HeaderTo(w io.StringWriter, title string)

func RedS

func RedS(s string) string

func Spark added in v0.4.0

func Spark(counts map[int]int, width int) string

Spark renders a sparkline from a sparse bucket→count map. Each of the width positions maps to a SparkBlocks character whose level is proportional to its count relative to maxCount. Useful for rendering Probability Density Function (PDF) - X is value, Y is % of population.

func SparkLine added in v0.4.0

func SparkLine(vals []int, maxVal, width int) string

SparkLine renders a sparkline from a slice of values. Each value is mapped to a SparkBlocks character proportional to maxVal. The result is stretched to width characters.

func VolumeBar

func VolumeBar[T int | int32 | int64 | float32 | float64](v, max T, width int) string

func VolumeBar2 added in v0.5.1

func VolumeBar2[T int | int32 | int64](a, b, max T, width int) string

func YellowS

func YellowS(s string) string

Types

type Alignment

type Alignment uint8
const (
	AlignUndefined Alignment = iota
	AlignLeft
	AlignRight
)

func (Alignment) Write

func (a Alignment) Write(out interface{ WriteString(string) (int, error) }, s string, width int)

type TablCol

type TablCol struct {
	Header    string
	Alignment Alignment
	Width     int
}

func (TablCol) Write

func (s TablCol) Write(out interface{ WriteString(string) (int, error) }, v string)

type TableWriter

type TableWriter struct {
	Indent string
	Cols   []TablCol
	Out    interface {
		WriteString(s string) (n int, err error)
	}
}

TableWriter provides simple table formatting with ANSI color support. Values that are too long will get truncated into column width.

func (TableWriter) WriteHeader

func (s TableWriter) WriteHeader()

func (TableWriter) WriteHeaderLine

func (s TableWriter) WriteHeaderLine()

func (TableWriter) WriteRow

func (s TableWriter) WriteRow(vs ...string)

func (TableWriter) WriteSubHeader

func (s TableWriter) WriteSubHeader(vs ...string)

Jump to

Keyboard shortcuts

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