Skip to main content

kronos_tide/
unicode.rs

1use unicode_width::UnicodeWidthChar;
2
3/// Display width of a Unicode character for terminal rendering.
4///
5/// Returns:
6///   0 — combining/zero-width character; caller appends to previous cell
7///   1 — normal single-column character
8///   2 — wide character (CJK ideograph, some emoji); occupies two columns
9///
10/// Characters with unknown width (e.g. private-use) are treated as width 1.
11pub fn char_width(ch: char) -> usize {
12    UnicodeWidthChar::width(ch).unwrap_or(1)
13}
14
15/// True if `ch` is a combining (zero-width) mark.
16#[allow(dead_code)]
17pub fn is_combining(ch: char) -> bool {
18    char_width(ch) == 0 && ch != '\x00'
19}
20
21/// True if `ch` occupies two columns (CJK, wide emoji, etc.).
22#[allow(dead_code)]
23pub fn is_wide(ch: char) -> bool {
24    char_width(ch) == 2
25}