Expand description
Β§runefix-core
Unicode-aware display width engine for terminals, TUI, and Markdown rendering.
runefix-core
provides precise width computation for multilingual text,
with support for:
- East Asian fullwidth characters (CJK)
- Emoji (including multi-codepoint ZWJ sequences)
- Fullwidth punctuation and symbol variants
- Grapheme-aware string truncation and wrapping
It ensures consistent text alignment across platforms and fonts by working at the grapheme cluster level, consulting curated Unicode-derived datasets.
Β§Features
𧬠Atom API
atoms
β Runefix-specific visual segmentation for layout (width-based units)
π§© Segmentation API
graphemes
β Unicode-compliant grapheme cluster splitting (UAX #29)
π Measurement API
display_width
β Total width of a string (grapheme-aware, terminal-style)display_widths
β Widths of each grapheme cluster (Vec<usize>
)grapheme_widths
β Widths with original clusters (Vec<(&str, usize)>
)
π Layout API
truncate_by_width
β Truncates text by width without splitting graphemessplit_by_width
β Wraps a string into lines based on terminal width
π Ergonomic Extensions
RuneDisplayWidth
β Trait for:.rune_width()
onchar
.width()
,.display_width()
,.display_widths()
onstr
Β§Example
use runefix_core::{RuneDisplayWidth, grapheme_widths};
assert_eq!('δ½ '.rune_width(), 2);
assert_eq!(
grapheme_widths("HiοΌδΈη"),
vec![("H", 1), ("i", 1), ("οΌ", 2), ("δΈ", 2), ("η", 2)]
);
Β§Resources
Note: Enable the
policy
feature to use configurable width strategies such asterminal()
,markdown()
, orcompact()
.
ConstantsΒ§
- UNICODE_
VERSION - Unicode Version used by this build (auto-synced). auto-updated: 2025-05-27
TraitsΒ§
- Rune
Display Width - Extension trait for measuring the display width of runes, graphemes, and strings.
FunctionsΒ§
- atoms
- Splits the input string into layout atoms β visual units used for width-aware layout.
- display_
width - Returns the total display width (in columns) of a string, based on grapheme clusters.
- display_
widths - Returns the display width (in columns) of each grapheme cluster in the input string.
- grapheme_
widths - Returns the display width of each grapheme cluster in the input string.
- graphemes
- Returns all Unicode grapheme clusters in the input string, following UAX #29.
- split_
by_ width - Splits a string into lines based on display width, preserving grapheme boundaries.
- truncate_
by_ width - Truncates a string by display width while preserving grapheme cluster boundaries.