Terminal-aware text utilities: visual column width, truncation, and padding that correctly handle multi-byte Unicode characters and wide glyphs (CJK ideographs, full-width forms, emoji) which occupy 2 terminal columns. More...
Static Public Member Functions | |
| static string | FitToWidth (string text, int targetWidth) |
| Right-pads or truncates text so its visual width equals exactly targetWidth terminal columns. | |
| static int | RuneDisplayWidth (Rune rune) |
| Returns the terminal display width of a single Rune: 2 for wide characters (CJK, full-width, most emoji), 1 for everything else. | |
| static string | TruncateToWidth (string text, int maxWidth) |
| Truncates text so its visual width does not exceed maxWidth terminal columns. | |
| static int | VisualWidth (ReadOnlySpan< char > text) |
| Returns the number of terminal columns occupied by the span. | |
| static int | VisualWidth (string text) |
| Returns the number of terminal columns occupied by text . | |
| static List< string > | WrapToWidth (string text, int width) |
| Splits text into lines of at most width terminal columns. | |
Terminal-aware text utilities: visual column width, truncation, and padding that correctly handle multi-byte Unicode characters and wide glyphs (CJK ideographs, full-width forms, emoji) which occupy 2 terminal columns.
Performance — All methods use string.IsAscii (SIMD-vectorized in .NET 8) as the primary fast-path gate. For pure-ASCII strings (the common case for widget labels and UI text) the hot path degenerates to a single vectorized scan plus O(1) arithmetic — no Rune enumeration, no StringBuilder allocation.
|
static |
Right-pads or truncates text so its visual width equals exactly targetWidth terminal columns.
Wide characters that would overflow by exactly 1 column have a space substituted.
|
static |
Returns the terminal display width of a single Rune: 2 for wide characters (CJK, full-width, most emoji), 1 for everything else.
Uses codepoint range arithmetic — no allocation.
|
static |
Truncates text so its visual width does not exceed maxWidth terminal columns.
Returns the original string reference unchanged when it already fits.
|
static |
Returns the number of terminal columns occupied by text .
Pure ASCII strings return text.Length via a single SIMD scan. Wide characters (CJK, emoji, full-width) count as 2 columns.
|
static |
Splits text into lines of at most width terminal columns.
Hard newlines in the source always produce a line break.