TuiString
Width-aware string helpers. Everything here measures in terminal CELLS, not bytes or code points, and ignores ANSI sequences — a renderer that measured in bytes would not produce a wrong string, it would corrupt the frame, because the buffer composites at bounds without clamping.
TuiString::clean()
public static function clean(string $text): stringStrips control characters that would corrupt the frame, leaving printable text and ANSI styling intact.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string |
TuiString::stripAnsi()
public static function stripAnsi(string $text): stringThe text with every ANSI escape sequence removed.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string |
TuiString::visibleLength()
public static function visibleLength(string $text): intThe width the text occupies in terminal cells, ignoring ANSI sequences and counting wide graphemes as the columns they really take.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string |
TuiString::truncate()
public static function truncate(string $text, int $width, string $ellipsis = '…'): stringThe text cut to fit the width, ending in the ellipsis when something was removed. Text that already fits is returned unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string | |
| $width | int | |
| $ellipsis | string |
TuiString::padEnd()
public static function padEnd(string $text, int $width): stringThe text padded with spaces to exactly the given cell width.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string | |
| $width | int |
TuiString::cells()
public static function cells(string $text): arrayThe text split into one entry per terminal cell.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string |
TuiString::slice()
public static function slice(string $text, int $width): stringThe leading portion of the text that fits the width, without an ellipsis.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string | |
| $width | int |
TuiString::sliceFrom()
public static function sliceFrom(string $text, int $start): stringThe complement of {@see self::slice()}: everything from the given visible-column offset onward, mb-aware.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string | |
| $start | int |
TuiString::wordwrap()
public static function wordwrap(string $text, int $width, string $break = '
'): stringMb-aware equivalent of PHP's `wordwrap($text, $width, $break, true)` -- wraps on word boundaries and hard-breaks any single word wider than $width, but measures/cuts by visible columns (via {@see self::visibleLength()}/{@see self::slice()}) instead of bytes, so multibyte content (accents, emoji) wraps at the same width a plain-ASCII string of that length would.
Parameters
| Name | Type | Description |
|---|---|---|
| $text | string | |
| $width | int | |
| $break | string |