Documentation
¶
Overview ¶
Package text provides small formatting helpers shared by command output: rune-safe truncation, compact relative timestamps, and byte sizes.
Index ¶
- func DisplayWidth(s string) int
- func EscapeTSVCell(s string) string
- func FormatBytes(n int64) string
- func Pluralize(n int, singular, plural string) string
- func RelativeTime(t, now time.Time) string
- func SanitizeTerminal(s string) string
- func SanitizeTerminalInline(s string) string
- func Truncate(max int, s string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisplayWidth ¶ added in v0.2.1
DisplayWidth reports how many terminal columns s occupies: East Asian wide and fullwidth runes take two, combining marks and format characters take none, everything else takes one.
Column alignment must be computed with this rather than a rune count. Melange output carries server-supplied text — device marketing names above all — and a single CJK character in one cell shifts every column to its right when padding is counted in runes.
func EscapeTSVCell ¶
EscapeTSVCell makes one value safe for the CLI's line-oriented TSV contract. Printable content is unchanged; backslashes and record/column control characters use reversible backslash escapes.
func FormatBytes ¶
FormatBytes renders n in binary units (KiB/MiB/GiB) with one decimal. Values below 1 KiB are plain bytes; values beyond 1 GiB stay in GiB.
func Pluralize ¶ added in v0.2.1
Pluralize renders a count with its noun: "1 repository", "3 repositories". Both forms are spelled out by the caller because English plurals the CLI needs are not all formed by appending "s".
func RelativeTime ¶
RelativeTime renders t relative to now in a compact form: "just now", "5m ago", "3h ago", "2d ago", and an absolute "Jan 2, 2006" date beyond 30 days. Future timestamps render as "just now".
func SanitizeTerminal ¶
SanitizeTerminal removes terminal escape/control sequences from untrusted human-readable text. Newlines and tabs are retained so block layout remains readable; all other C0/C1 controls are removed. OSC, CSI, and related string controls are consumed through their terminator so their payload cannot be reinterpreted or copied into a terminal.
func SanitizeTerminalInline ¶
SanitizeTerminalInline is SanitizeTerminal for table cells and other single-line fields. Layout controls become spaces rather than new rows.
Types ¶
This section is empty.