diff options
| author | Julian Hurst <ark@mansus.space> | 2025-03-21 19:24:20 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2025-03-21 19:24:20 +0100 |
| commit | c5c9ba1d277859ce48ba3bfb77e05b2cc0b0fe3e (patch) | |
| tree | b7b572e8e1cf75c5cd5437f9b300d488ec9bb266 | |
| parent | 158fe9ad854f6e902a12e13541f948ddc7e4b8ab (diff) | |
| parent | c117966782fe826ae0146467dacb4ad20893046e (diff) | |
| download | hare-tui-c5c9ba1d277859ce48ba3bfb77e05b2cc0b0fe3e.tar.gz | |
Merge branch 'master' into nomem
| -rw-r--r-- | tests/runewidth.ha | 16 | ||||
| -rw-r--r-- | tests/strwidth.ha | 2 | ||||
| -rw-r--r-- | tui/width.ha | 37 |
3 files changed, 55 insertions, 0 deletions
diff --git a/tests/runewidth.ha b/tests/runewidth.ha index 5e570a5..820dcf0 100644 --- a/tests/runewidth.ha +++ b/tests/runewidth.ha @@ -6,4 +6,20 @@ fn runewidth() void = { assert(tui::runewidth('ๅคง') == 2); assert(tui::runewidth('ใ') == 2); assert(tui::runewidth('๐') == 2); + assert(tui::runewidth('่ฟ') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใฎ') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('๐ช') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใพ') == 2); + assert(tui::runewidth('่ก') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใช') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใ') == 2); + assert(tui::runewidth('ใ') == 2); }; diff --git a/tests/strwidth.ha b/tests/strwidth.ha index e3863d6..2024ca9 100644 --- a/tests/strwidth.ha +++ b/tests/strwidth.ha @@ -3,4 +3,6 @@ use tui; @test fn strwidth() void = { assert(tui::strwidth("ๅคงใ๐f") == 7); + assert(tui::strwidth("่ฟใ้ ใใฎใใใใ๐ชใใพ่กใใชใใใใ") == 38); + assert(tui::strwidth("ํ๋ฌ๋ฝ๋ชจ์จฉ็ใใฎใใผใฉใผใกใใ") == 30); }; diff --git a/tui/width.ha b/tui/width.ha index f6d6078..cb4464a 100644 --- a/tui/width.ha +++ b/tui/width.ha @@ -1,5 +1,6 @@ use strings; +//https://unicodeplus.com/ export fn runewidth(r: rune) uint = { let ru = r: u32; // emoticons: https://en.wikipedia.org/wiki/Emoticons_(Unicode_block) @@ -18,6 +19,42 @@ export fn runewidth(r: rune) uint = { if (ru >= '\U00004E00' && ru <= '\U00009FFF') { return 2; }; + // CJK Symbols and Punctuation: https://en.wikipedia.org/wiki/CJK_Symbols_and_Punctuation + if (ru >= '\U00003000' && ru <= '\U0000303F') { + return 2; + }; + // Hangul Syllables: https://en.wikipedia.org/wiki/Hangul_Syllables + if (ru >= '\U0000AC00' && ru <= '\U0000D7AF') { + return 2; + }; + // Miscellaneous Symbols: https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs + if (ru >= '\U00002600' && ru <= '\U000026FF') { + return 2; + }; + // Miscellaneous Symbols and Pictographs: https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Pictographs + if (ru >= '\U0001F300' && ru <= '\U0001F5FF') { + return 2; + }; + // Dingbats: https://en.wikipedia.org/wiki/Dingbats_(Unicode_block) + if (ru >= '\U00002700' && ru <= '\U000027BF') { + return 2; + }; + // Transport and Map symbols: https://en.wikipedia.org/wiki/Transport_and_Map_Symbols + if (ru >= '\U0001F680' && ru <= '\U0001F6FF') { + return 2; + }; + // Supplemental Symbols and Pictographs: https://en.wikipedia.org/wiki/Supplemental_Symbols_and_Pictographs + if (ru >= '\U0001F900' && ru <= '\U0001F9FF') { + return 2; + }; + // Miscellaneous Symbols and Arrows: https://en.wikipedia.org/wiki/Miscellaneous_Symbols_and_Arrows + if (ru >= '\U00002B00' && ru <= '\U00002BFF') { + return 2; + }; + // Symbols and Pictographs Extended-A: https://en.wikipedia.org/wiki/Symbols_and_Pictographs_Extended-A + if (ru >= '\U0001FA70' && ru <= '\U0001FAFF') { + return 2; + }; return 1; }; |
