Skip to main content

Module formatting

Module formatting 

Source
Expand description

Unified formatting utilities for UI and logging

Functionsยง

collapse_whitespace
Collapse consecutive whitespace into single spaces, trimming leading/trailing.
format_size
Format file size in human-readable form (KB, MB, GB, etc.)
head_tail_truncate
Truncate value to max_chars chars by keeping a head and a tail joined by marker, preserving context from both ends of the text.
indent_block
Indent a block of text with the given prefix
truncate_byte_budget
Truncate a string so that the retained prefix is at most max_bytes bytes, rounded down to the nearest UTF-8 char boundary. Returns the truncated prefix with suffix appended, or the original string when it already fits.
truncate_text
Truncate text to a maximum length (in chars) with an optional ellipsis.
truncate_within
Truncate text to max_len chars, reserving room for ellipsis so the returned string never exceeds max_len chars.
wrap_text_words
Word-wrap text into lines, allowing first_width chars on the first line and continuation_width chars on subsequent lines. Wrapping prefers whitespace boundaries and is UTF-8 safe (widths count chars, not bytes).