Expand description
Unified formatting utilities for UI and logging
Constants§
- RAN_
COMMAND_ CONTINUATION_ WIDTH - Continuation-line budget for
RAN_COMMAND_FIRST_WIDTHheaders. - RAN_
COMMAND_ FIRST_ WIDTH - Shared
• Ranheader wrap widths so every tool-call command surface stays in sync: 62 chars for the first line (• Ranprefix), 58 for continuations (│prefix). All surfaces wrap the full command withwrap_shell_command_with_continuations(explicit\, no…); TUI reflow owns any residual viewport overflow.
Functions§
- clean_
reasoning_ text - Clean reasoning text by trimming trailing whitespace on each line and removing blank lines.
- collapse_
whitespace - Collapse consecutive whitespace into single spaces, trimming leading/trailing.
- compact_
reasoning_ text - Compact reasoning text for on-screen display.
- contains_
ignore_ ascii_ case - Case-insensitive ASCII substring search that does not allocate a lowercased copy of either input.
- format_
float_ display - Format an
f64float for display, collapsing decimal artifacts. - format_
size - Format file size in human-readable form (KB, MB, GB, etc.)
- head_
tail_ truncate - Truncate
valuetomax_charschars by keeping a head and a tail joined bymarker, preserving context from both ends of the text. - humanize_
duration_ compact - Format a duration in seconds as a compact human-readable unit.
- indent_
block - Indent a block of text with the given prefix
- is_
markdown_ fence_ delimiter - Whether
lineopens or closes a fenced markdown code block. - lowercase_
leading_ word - Lowercase a leading capitalized plain word so
textreads as a clause continuing a sentence (for example after a colon). Acronyms and identifiers (a second uppercase letter, a digit, or punctuation after the first letter) and the pronoun “I” keep their case. - strip_
optional_ word_ prefix - Strip an optional leading
word(case-insensitive) that is separated from the rest by whitespace, returning the trimmed remainder, orinputunchanged when the prefix is absent or not word-boundary separated. - trim_
wrapping_ quotes_ and_ punctuation - Trim surrounding whitespace, matched wrapping quotes (
"/'), and trailing sentence punctuation (. , ; ! ?), repeating until the value is stable. - truncate_
byte_ budget - Truncate a string so that the retained prefix is at most
max_bytesbytes, rounded down to the nearest UTF-8 char boundary. Returns the truncated prefix withsuffixappended, or the original string when it already fits. - truncate_
middle - Truncate
textto at mostmax_lenchars, keeping a head and a tail joined by a single…so context from both ends is preserved. - truncate_
path_ middle - Truncate a file path in the middle, preferring to break at path separators.
- truncate_
text - Truncate text to a maximum length (in chars) with an optional ellipsis.
- truncate_
utf8_ prefix - Borrow the longest prefix of
textthat is at mostmax_bytesbytes, rounded down to the nearest UTF-8 char boundary. - truncate_
within - Truncate text to
max_lenchars, reserving room forellipsisso the returned string never exceedsmax_lenchars. - wrap_
shell_ command - Word-wrap a shell
commandinto lines, allowingfirst_widthchars on the first line andcontinuation_widthchars on subsequent lines. - wrap_
shell_ command_ lines - Operator-aware word-wrap of a shell
commandwithout continuation markers. - wrap_
shell_ command_ with_ continuations - Word-wrap a shell
commandinto display lines with explicit\continuations, so multi-line tool-call headers read as valid shell. - wrap_
text_ words - Word-wrap
textinto lines, allowingfirst_widthchars on the first line andcontinuation_widthchars on subsequent lines. Wrapping prefers whitespace boundaries and is UTF-8 safe (widths count chars, not bytes).