cjk-align

Crates.iocjk-align
lib.rscjk-align
version0.1.0
sourcesrc
created_at2024-03-29 14:19:33.958441
updated_at2024-03-29 14:19:33.958441
descriptionAlign CJK and emoji characters correctly on terminals
homepage
repositoryhttps://github.com/lilydjwg/cjk-align
max_upload_size
id1190161
size6,049
Rust-publish (github:flatbuffers:rust-publish)

documentation

README

This library provides a wrapper struct CJKAlign to align CJK and emoji characters correctly on terminals. Despite its name, it works for other Unicode characters too as supported by the unicode-width crate.

use cjk_align::CJKAlign;

assert_eq!(format!("{:6}", CJKAlign("你好")), "你好  ");
assert_eq!(format!("{:>6}", CJKAlign("你好")), "  你好");
assert_eq!(format!("{:^6}", CJKAlign("你好")), " 你好 ");
assert_eq!(format!("{:^7}", CJKAlign("你好")), "  你好 ");

To treat East Asian ambiguous width characters as double width, use CJKAlignWide instead:

use cjk_align::{CJKAlign, CJKAlignWide};

assert_eq!(format!("{:8}", CJKAlign("“……”")), "“……”    ");
assert_eq!(format!("{:8}", CJKAlignWide("“……”")), "“……”");
Commit count: 1

cargo fmt