Expand description
Text wrapping with Unicode correctness.
This module provides width-correct text wrapping that respects:
- Grapheme cluster boundaries (never break emoji, ZWJ sequences, etc.)
- Cell widths (CJK characters are 2 cells wide)
- Word boundaries when possible
§Example
use ftui_text::wrap::{wrap_text, WrapMode};
// Word wrap
let lines = wrap_text("Hello world foo bar", 10, WrapMode::Word);
assert_eq!(lines, vec!["Hello", "world foo", "bar"]);
// Character wrap (for long words)
let lines = wrap_text("Supercalifragilistic", 10, WrapMode::Char);
assert_eq!(lines.len(), 2);Structs§
- Break
Penalty - Penalty value for a break point.
- KpBreak
Result - Result of optimal line breaking.
- Paragraph
Objective - Configuration for the paragraph objective function.
- Wrap
Options - Options for text wrapping.
Enums§
- Break
Kind - Type of break point in the paragraph item stream.
- Fitness
Class - Fitness class for a line based on its adjustment ratio.
- Wrap
Mode - Text wrapping mode.
Functions§
- ascii_
width - Returns
Some(width)if text is printable ASCII only,Noneotherwise. - display_
width - Calculate the display width of text in cells.
- grapheme_
count - Count the number of grapheme clusters in a string.
- grapheme_
width - Calculate the display width of a single grapheme cluster.
- graphemes
- Iterate over grapheme clusters in a string.
- has_
wide_ chars - Check if a string contains any wide characters (width > 1).
- is_
ascii_ only - Check if a string is ASCII-only (fast path possible).
- truncate_
to_ width - Truncate text to exactly fit within a width (no ellipsis).
- truncate_
to_ width_ with_ info - Truncate text to fit within a maximum display width.
- truncate_
with_ ellipsis - Truncate text to fit within a width, adding ellipsis if needed.
- word_
boundaries - Find word boundary positions suitable for line breaking.
- word_
segments - Split text into word segments preserving boundaries.
- wrap_
optimal - Compute optimal line breaks using Knuth-Plass DP.
- wrap_
text - Wrap text to the specified width.
- wrap_
text_ optimal - Wrap text optimally, returning just the lines (convenience wrapper).
- wrap_
with_ options - Wrap text with full options.