display

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package display is the one canonical sanitizer for anything a hostile or careless bus payload (subject, body, reply preview) could put in front of an operator's terminal: the renderer, journal preview columns, and the station TUI all funnel through Sanitize rather than each rolling their own escaping. It has no dependency on internal/humancli or internal/daemon so the daemon can sanitize at journal time without importing the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sanitize

func Sanitize(s string, maxWidth int) string

Sanitize strips control characters that could corrupt a terminal or a TUI pane — C0/C1 controls, NUL, full ESC/CSI escape sequences, and Unicode bidi override characters (U+202A-202E, U+2066-2069) — collapses runs of tab/newline/CR into a single space, and truncates the result to maxWidth display columns (wide/combining runes counted properly, not rune count), appending '…' when truncation actually cuts content. maxWidth <= 0 yields "" (there is no room even for the ellipsis). This is the one-line contract: every caller that renders a single terminal row (journal preview columns, the station TUI's list/status rows) funnels through this. A caller that needs to keep a multi-line body's paragraph/list structure — the station conversation view's message bodies — wants SanitizeLines instead, which shares this function's exact character-level cleaning via cleanControls but preserves newlines rather than collapsing them to spaces.

func SanitizeLines

func SanitizeLines(s string) []string

SanitizeLines cleans a multi-line body with the SAME character-level scrubbing Sanitize uses — C0/C1 controls, NUL, full ESC/CSI escape sequences, 8-bit and UTF-8-encoded C1 introducers, and Unicode bidi override characters — but, unlike Sanitize, preserves newlines (and blank lines) instead of collapsing them to a single space, then splits the result into lines. Intra-line runs of tab/CR still collapse to a single space exactly as Sanitize's do; only '\n' survives as a literal line break. No width cap: callers (the station conversation body path) wrap each returned line to their pane's width themselves, since word-wrapping a multi-line body needs per-line control the single maxWidth-and-truncate contract above doesn't offer.

func Width

func Width(s string) int

Width returns the total terminal display width of s (see runeWidth).

Types

This section is empty.

Jump to

Keyboard shortcuts

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