Skip to content

lilydjwg/cjk-align

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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("“……”")), "“……”");

About

Align CJK and emoji characters correctly on terminals

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages