Documentation
¶
Overview ¶
Package textutil holds small string helpers shared by tools and the TUI.
Package textutil holds small string helpers shared by tools and the TUI.
Index ¶
- func Ellipsize(s string, n int) string
- func ExpandBraces(glob string) []string
- func GlobToRegex(glob string) string
- func HTMLToText(src string) string
- func SanitizeTerminal(s string) string
- func Tail(s string, n int) string
- func TrimPartialRune(s string) string
- func TruncateUTF8(s string, n int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandBraces ¶ added in v0.9.1
ExpandBraces makes one glob of each {a,b} alternative ("**/*.{pem,key}": "**/*.pem" and "**/*.key"), nested and repeated braces too. A brace without a comma, or unclosed, stays as written; more than 64 globs is none expanded, the glob as written.
func GlobToRegex ¶
GlobToRegex converts a slash-separated glob to an unanchored regex body using only syntax understood by both Go and the macOS sandbox profile language: *, ** and ? as wildcards, and a class, [abc], [a-z] or [!abc] (never a slash). Braces aren't alternatives here: ExpandBraces makes one glob of each first. Anything else is quoted, so the result always compiles.
func HTMLToText ¶ added in v0.7.0
HTMLToText extracts readable text from HTML: scripts and styles are dropped, block elements become line breaks, headings and list items keep light Markdown markers, and links keep their absolute targets.
func SanitizeTerminal ¶
SanitizeTerminal strips control characters that a terminal would interpret (ESC sequences, BEL, backspace, carriage return, C1 controls) so untrusted text from models, files, or tool output cannot rewrite the screen, change the window title, or write to the clipboard via OSC 52. Newlines and tabs are kept. Invalid UTF-8 is replaced with U+FFFD.
func Tail ¶ added in v0.8.3
Tail is the end of s, at most n bytes on a rune boundary, after "…" when cut: where a command's output says what went wrong.
func TrimPartialRune ¶
TrimPartialRune drops an incomplete multi-byte rune from the end of s, as left behind when a byte stream is cut at an arbitrary offset.
func TruncateUTF8 ¶
TruncateUTF8 returns s cut to at most n bytes without splitting a multi-byte rune.
Types ¶
This section is empty.