Crate runefix_core

Source
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

🍭 Ergonomic Extensions

  • RuneDisplayWidth – Trait for:
    • .rune_width() on char
    • .width(), .display_width(), .display_widths() on str

Β§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 as terminal(), markdown(), or compact().

ConstantsΒ§

UNICODE_VERSION
Unicode Version used by this build (auto-synced). auto-updated: 2025-05-27

TraitsΒ§

RuneDisplayWidth
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.