Skip to main content

Module wrap

Module wrap 

Source
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§

KpBreakResult
Result of optimal line breaking.
WrapOptions
Options for text wrapping.

Enums§

WrapMode
Text wrapping mode.

Functions§

ascii_width
Returns Some(width) if text is printable ASCII only, None otherwise.
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.