Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lilydjwg/cjk-align
Align CJK and emoji characters correctly on terminals
https://github.com/lilydjwg/cjk-align
cjk cjk-characters rust-library
Last synced: about 2 months ago
JSON representation
Align CJK and emoji characters correctly on terminals
- Host: GitHub
- URL: https://github.com/lilydjwg/cjk-align
- Owner: lilydjwg
- License: bsd-3-clause
- Created: 2024-03-29T14:18:46.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-03-29T14:19:10.000Z (9 months ago)
- Last Synced: 2024-10-07T22:38:07.608Z (3 months ago)
- Topics: cjk, cjk-characters, rust-library
- Language: Rust
- Homepage:
- Size: 1.95 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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.```rust
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:```rust
use cjk_align::{CJKAlign, CJKAlignWide};assert_eq!(format!("{:8}", CJKAlign("“……”")), "“……” ");
assert_eq!(format!("{:8}", CJKAlignWide("“……”")), "“……”");
```