formatter

package module
v0.0.0-...-f1321f6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ANSIReset = "\x1b[m"
View Source
const MaskReplacementValue = "***"
View Source
const TruncateEllipsis = "…" // Should be 1 character wide.

Variables

This section is empty.

Functions

func Clusters

func Clusters(input string) iter.Seq[string]

Clusters returns an iterator of grapheme clusters from the input string.

func CutMultiline

func CutMultiline(s string, left, right int) string

func Duration

func Duration(d time.Duration, rel int) string

Duration formats a duration, and optionally adds a relative prefix/suffix. If rel is 0, then the duration is formatted without a relative prefix/suffix. If rel is 1, it is considered in the future. If rel is -1, it is considered in the past.

func IsFlatValue

func IsFlatValue[T comparable](data map[T]any) bool

IsFlatValue returns true when the map values provided is a flat value (can be rendered into a 1 dimensional list).

func MaskValue

func MaskValue(v any) any

MaskValue recursively masks concrete values in the data structure.

func PadMinimum

func PadMinimum(s string, minWidth int) string

PadMinimum pads a string to a minimum width, adding even padding on both sides of the string if the string is shorter than the minimum width.

func Time

func Time(t time.Time) string

Time formats a time.Time as a full string (date, time, timezone).

func TimeRelative

func TimeRelative(t time.Time, postfix bool) string

TimeRelative formats a time.Time as a relative string (e.g. "in 10 seconds", "10 seconds ago", "now", "n/a" for zero value).

func ToJSON

func ToJSON(data any, mask bool, indent int) string

ToJSON will convert the provided data value into JSON. If mask is true, all concrete values will be masked with asterisks.

func ToYAML

func ToYAML(data any, mask bool, indent int) string

ToYAML will convert the provided data value into a YAML string, optionally masking the values if the mask flag is true.

func Trunc

func Trunc(s string, length int) string

Trunc truncates a string to a given length, adding a tail to the end if the string is longer than the given length. This function is aware of ANSI escape codes and will not break them, and accounts for wide-characters (such as East-Asian characters and emojis). This treats the text as a sequence of graphemes.

func TruncLeft

func TruncLeft(s string, length int) string

func TruncLeftMultiline

func TruncLeftMultiline(s string, length int) string

func TruncMaybePath

func TruncMaybePath(s string, length int) string

TruncMaybePath truncates a string similar to Trunc, but if one of the parts of the string looks like a path, it will be truncated using TruncPath.

func TruncMultiline

func TruncMultiline(s string, length int) string

TruncMultiline is similar to Trunc, but it truncates each line of a multiline string separately.

func TruncPath

func TruncPath(s string, length int) string

TruncPath dynamically truncates a path to a given length, prioritizing keeping both start and end segments when possible.

func TruncReset

func TruncReset(s string) string

TruncReset removes the ANSI reset sequence from a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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