tuiutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration renders a time.Duration in compact form for TUI dashboards: "523ms" / "8.4s" / "1m42s".

func PadDisplayWidth

func PadDisplayWidth(s string, width int) string

PadDisplayWidth truncates or right-pads s with spaces so its display width is exactly width cells (ANSI-aware).

func PadDisplayWidthWith

func PadDisplayWidthWith(s string, width int, pad string) string

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

func SanitizeDisplayText(s string) string

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 StripANSI

func StripANSI(s string) string

StripANSI removes ANSI escape sequences from s.

func TruncateDisplayWidth

func TruncateDisplayWidth(s string, width int) string

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

func WrapDisplayWidth(s string, width int) []string

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.

Jump to

Keyboard shortcuts

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