Skip to main content

Module text

Module text 

Source
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.
TextWrapMode
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_width for grapheme clusters.
char_index_from_cell_column
Maps a terminal column to the start of its grapheme, in character indices.
clip_to_cells
Clips s to at most max_cells terminal cells.
clip_to_cells_cow
Clips s to at most max_cells terminal cells, borrowing s when no clipping or character normalization is required.
clip_to_cells_ellipsis
Clips s to max_cells like clip_to_cells, but appends an ellipsis if clipped.
clip_to_cells_into
Clips s into an existing string buffer, reusing the allocation.
fit_to_cells
Pads or truncates s to exactly target_cells cells.
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_cells terminal columns.
wrap_to_cells
Wraps plain text into renderable lines, expanding tabs and removing controls.