Expand description
Text utilities for terminal rendering.
This module intentionally focuses on terminal cell concepts (columns/rows), not on rich text editing. The editor crate can own the higher-level buffer, undo/redo, and modal behavior.
The helpers here are aimed at:
- status bars / command lines
- horizontal clipping / truncation
- “fit this string into N terminal columns”
Width and clipping use complete grapheme clusters and Unicode width tables, including emoji sequences, combining marks, and wide CJK characters.
Enums§
- TabPolicy
- How to handle tab characters (
'\t') when measuring/clipping text. - Text
Wrap Mode - Where to break text that exceeds the available terminal cells.
Functions§
- byte_
index_ for_ char_ index - Converts a character index into a byte index for
s. - byte_
index_ for_ grapheme_ index - Converts a grapheme index into a byte index for
s. - cell_
column_ for_ char_ index - Returns the terminal cell column for a character index in
s. - cell_
column_ for_ grapheme_ index - Returns the terminal cell column for a grapheme index in
s. - cell_
width - Returns the terminal width of complete grapheme clusters, ignoring controls.
- cell_
width_ char - Returns the width of a Unicode scalar. Use
cell_widthfor grapheme clusters. - char_
index_ from_ cell_ column - Maps a terminal column to the start of its grapheme, in character indices.
- clip_
to_ cells - Clips
sto at mostmax_cellsterminal cells. - clip_
to_ cells_ cow - Clips
sto at mostmax_cellsterminal cells, borrowingswhen no clipping or character normalization is required. - clip_
to_ cells_ ellipsis - Clips
stomax_cellslikeclip_to_cells, but appends an ellipsis if clipped. - clip_
to_ cells_ into - Clips
sinto an existing string buffer, reusing the allocation. - fit_
to_ cells - Pads or truncates
sto exactlytarget_cellscells. - grapheme_
count - Returns the number of grapheme clusters in
s. - grapheme_
index_ from_ cell_ column - Best-effort mapping from terminal cell column to grapheme index.
- wrap_
ranges_ to_ cells - Returns source byte ranges for lines wrapped to
max_cellsterminal columns. - wrap_
to_ cells - Wraps plain text into renderable lines, expanding tabs and removing controls.