tuiutil

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 5 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 SanitizeDisplayLine added in v0.13.0

func SanitizeDisplayLine(s string) string

SanitizeDisplayLine is SanitizeDisplayText for server text shown inline in a one-line message: it also drops bidi controls (U+202A–U+202E, U+2066–U+2069, and the other Bidi_Control runes), which are format characters rather than controls and could visually reorder the line.

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