Documentation
¶
Overview ¶
Package tuiutil hosts width-aware text helpers for fixed-width TUI dashboards: ANSI/control-char stripping, display-width-based truncation and padding, and a compact duration formatter.
Index ¶
- func FormatDuration(d time.Duration) string
- func PadDisplayWidth(s string, width int) string
- func PadDisplayWidthWith(s string, width int, pad string) string
- func SanitizeDisplayText(s string) string
- func StripANSI(s string) string
- func TruncateDisplayWidth(s string, width int) string
- func WrapDisplayWidth(s string, width int) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration renders a time.Duration in compact form for TUI dashboards: "523ms" / "8.4s" / "1m42s".
func PadDisplayWidth ¶
PadDisplayWidth truncates or right-pads s with spaces so its display width is exactly width cells (ANSI-aware).
func PadDisplayWidthWith ¶
PadDisplayWidthWith truncates or right-pads s with the pad string so its display width is exactly width cells. Pad strings whose display width is not 1 fall back to space padding to keep alignment predictable.
func SanitizeDisplayText ¶
SanitizeDisplayText strips ANSI escapes and control characters so the result is safe to render in a single-line table cell. Newlines and tabs collapse to a single space; carriage returns and other control runes are dropped entirely.
func TruncateDisplayWidth ¶
TruncateDisplayWidth shortens s so its display width is at most width cells, appending "…" as an ellipsis when truncation happens. Width 0 or less returns the empty string; width 1 truncates without an ellipsis since the ellipsis would consume the whole budget.
func WrapDisplayWidth ¶
WrapDisplayWidth wraps s to lines no wider than width display cells. Embedded '\n' characters are honored as paragraph boundaries: each paragraph is sanitized (ANSI/control stripped) and wrapped independently. A paragraph that wraps to nothing still contributes an empty line, preserving blank-line structure between paragraphs.
Trailing newlines are stripped before splitting so "text\n" yields a single line, not a phantom blank tail.
Returns nil for width <= 0 or input that is empty (or only newlines).
Types ¶
This section is empty.