spruce/align
ANSI-aware text alignment helpers.
Values
pub fn pad_center(text: String, width: Int) -> String
Pad text on both sides with spaces until it reaches width visual columns.
When an odd number of spaces is needed, the extra space is placed on the
right. Text already at or beyond width is returned unchanged.
pub fn pad_left(text: String, width: Int) -> String
Pad text on the left with spaces until it reaches width visual columns.
Text already at or beyond width is returned unchanged.
pub fn pad_right(text: String, width: Int) -> String
Pad text on the right with spaces until it reaches width visual columns.
Text already at or beyond width is returned unchanged.
pub fn size(text: String) -> #(Int, Int)
Return the widest visual line and the number of lines in text.
pub fn truncate(
text: String,
width width: Int,
ellipsis ellipsis: String,
) -> String
Truncate text to at most width visual columns, appending ellipsis when
truncation is needed.
ANSI escape sequences do not count toward the width and are never split.
If ellipsis is wider than width, the ellipsis itself is visibly
truncated to fit. Widths less than or equal to zero return an empty string.
pub fn visual_length(text: String) -> Int
The visual length of a string, excluding ANSI escape codes.