| Crates.io | runefix-core |
| lib.rs | runefix-core |
| version | 0.1.10 |
| created_at | 2025-05-25 02:41:01.740799+00 |
| updated_at | 2025-05-31 11:24:02.621015+00 |
| description | Unicode character display width engine supporting CJK, emoji, and grapheme clusters |
| homepage | https://github.com/runefix-labs/runefix-core |
| repository | https://github.com/runefix-labs/runefix-core |
| max_upload_size | |
| id | 1687950 |
| size | 1,484,578 |
๐ฏ A Rust core library that fixes terminal and Markdown misalignment caused by CJK and emoji widths.
English | ็ฎไฝไธญๆ | ๆฅๆฌ่ช
runefix-core is a Unicode-based display width engine that provides precise character width calculation, designed for:
Its goal is to solve a decades-long problem: misaligned characters in terminal and UI environments due to inconsistent Unicode width handling. This includes:
CJK characters (Chinese, Japanese, Korean), Kana, and Hangul syllables
Emoji (base, composite, and flag sequences)
Fullwidth punctuation and multilingual symbols
Grapheme cluster boundary cases
โ Precise width detection for emoji, CJK ideographs, Kana, Hangul, fullwidth symbols
โ
Unicode grapheme support via [graphemes()], compliant with [UAX #29]
โ
Custom atom segmentation via [atoms()], optimized for TUI/terminal layout
โ Width-aware formatting tools: truncate, wrap, split, measure
โ
Runtime layout strategies with [WidthPolicy] (terminal, markdown, compact)
โ
Trait extensions for char and str: .rune_width(), .display_width(), etc.
โ Zero dependencies, minimal build, embeddable in any CLI, TUI, or renderer
โ Fully reproducible width tables, auto-generated from char-table
โจ A runefix-specific alternative to Unicode graphemes
Unlike standard Unicode grapheme clusters (graphemes()), atoms() segments a string into layout-affecting units โ which directly map to visual space in terminal or TUI environments.
This segmentation is width-driven, optimized for rendering purposes:
use runefix_core::atoms;
let parts = atoms("๐ฉโโค๏ธโ๐โ๐จ");
assert_eq!(parts, vec!["๐ฉ", "\u{200d}", "โค", "\u{fe0f}", "\u{200d}", "๐", "\u{200d}", "๐จ"]);
This function is useful for:
Tips: ๐ง For Unicode-compliant grapheme segmentation, use [graphemes()].
๐งช
--features policyrequired
By default, runefix-core uses the terminal layout policy, where both emoji and CJK characters occupy 2 columns.
You can optionally enable runtime policies to adapt to other rendering environments:
# Cargo.toml
runefix-core = { version = "0.1", features = ["policy"] }
Then:
use runefix_core::{WidthPolicy, WithPolicy};
let policy = WidthPolicy::markdown();
let width = WithPolicy::new(&policy).apply("๐").display_width();
assert_eq!(width, 1); // markdown prefers emoji width = 1
โน๏ธ Note: Some advanced methods (like .truncate_by_width(...)) may require intermediate bindings due to borrowing rules of &str. See with_policy.rs for idiomatic usage.
| Policy | Emoji | CJK | Variant | Use case |
|---|---|---|---|---|
terminal() |
2 | 2 | 2 | Default. Best for terminal apps |
markdown() |
1 | 2 | 2 | GitHub / Typora / table renderers |
compact() |
1 | 1 | 1 | Logs, status bars, tight layouts |
You can also override policies dynamically at runtime for your renderer.
use runefix_core::RuneDisplayWidth;
fn main() {
println!("{}", "ไฝ ".rune_width()); // Output: 2
println!("{}", "๐".rune_width()); // Output: 2
println!("{}", "ไฝ a1๐".display_width()); // Output: 6
}
For a full demo of grapheme-aware alignment and terminal behavior, see examples/text_align.rs.
It showcases:
.chars().count() โrunefix_core::RuneDisplayWidth โ
๐ Read more in examples/README.md
Add the following to your Cargo.toml:
# Stable release (recommended)
runefix-core = "0.1"
See crates.io for the latest version.
๐ฅ๏ธ Terminal alignment (CLI box drawing, tables)
๐งพ Markdown renderers (accurate width handling in table cells)
๐ TUI layout engines (React-style terminal UIs)
๐ Editors and terminal emulators (accurate text wrapping)
๐งฉ Width testing tools, playgrounds, and visualization platforms
This crate relies on structured, versioned datasets from char-table, including:
emoji_base.json, emoji_zwj.jsoncjk_unified.json, japanese_kana.json, korean_syllables.jsonfullwidth_variants.json, fullwidth_punctuations.jsonAll datasets are reproducible, regularly updated, and aligned with the latest Unicode releases.
| Module | Status |
|---|---|
| CJK width detection | โ Completed |
| Emoji width support | โ Completed |
| Grapheme cluster | โ Completed |
See CHANGELOG.md for version history.
MIT OR Apache-2.0
ยฉ 2025 Pokeya Z. Chen / Runefix Labs
This project is maintained by the runefix-labs organization. It serves as the core engine for the runefix suite โ a multi-language, cross-platform solution for Unicode width handling.
GitHub: github.com/runefix-labs
Author: pokeyaro
Email: pokeya.mystic@gmail.com