Crate runefix_core

Source
Expand description

§runefix-core

Unicode-aware display width engine for terminals, TUI, and Markdown rendering.

This crate provides precise width computation for multilingual text, including:

  • East Asian fullwidth characters (CJK)
  • Emoji (including ZWJ sequences)
  • Fullwidth punctuation and symbol variants
  • Grapheme-aware string truncation and wrapping

It ensures text alignment is consistent across platforms and fonts by working at the grapheme cluster level and consulting curated Unicode-derived datasets.

§Features

  • get_display_width: Width of a single grapheme or string
  • split_graphemes: Unicode-aware character segmentation
  • truncate_by_width: Safe truncation without splitting emoji/CJK
  • split_by_width: Line wrapping by column width

§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)]
);

See README for dataset source and usage details.

Constants§

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

Traits§

RuneDisplayWidth
Extension trait for measuring the display width of runes, graphemes, and strings.

Functions§

display_width
Re-exports: Primary public API Returns the total display width (in columns) of a string, based on grapheme clusters.
display_widths
Re-exports: Primary public API Returns the display width (in columns) of each grapheme cluster in the input string.
grapheme_widths
Re-exports: Primary public API Returns the display width of each grapheme cluster in the input string.
split_by_width
Re-exports: Primary public API Splits a string into lines based on display width, preserving grapheme boundaries.
split_graphemes
Re-exports: Primary public API Returns all grapheme clusters in the input string as a vector of string slices.
truncate_by_width
Re-exports: Primary public API Truncates a string by display width while preserving grapheme cluster boundaries.