tuiutil

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 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 SanitizeTerminalLabel added in v0.11.0

func SanitizeTerminalLabel(s string) string

SanitizeTerminalLabel is SanitizeTerminalText for width-aligned list labels: it additionally drops emoji skin-tone modifiers, zero-width joiners, and variation selectors, multi-codepoint sequences that confuse terminal width calculations. That normalization visibly mangles emoji in prose, so it is kept out of the general filter and applied only where a fixed-width line is actually being filled.

func SanitizeTerminalText added in v0.11.0

func SanitizeTerminalText(s string) string

SanitizeTerminalText strips ANSI escape sequences and non-printable runes from multi-line terminal output while preserving tabs and newlines. Unlike SanitizeDisplayText, which flattens text into a single table cell, this keeps line structure. It is the one filter for free-form session content (prompts, transcript text, summary bodies) printed to a terminal, so escape sequences carried in agent-influenced content cannot drive the reader's terminal.

Emoji sequences are deliberately left intact: this filter serves prose, where nothing is being width-aligned, and stripping joiners turns a family emoji into three separate people. SanitizeTerminalLabel is the variant for width-aligned labels.

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