diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/common/impl/wcwidth.c | |
Add the files
Diffstat (limited to 'src/common/impl/wcwidth.c')
| -rw-r--r-- | src/common/impl/wcwidth.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/common/impl/wcwidth.c b/src/common/impl/wcwidth.c new file mode 100644 index 0000000..4453510 --- /dev/null +++ b/src/common/impl/wcwidth.c @@ -0,0 +1,31 @@ +#include "common/wcwidth.h" +#include "3rdparty/widecharwidth/widechar_width_c.h" + +int mk_wcwidth(uint32_t wc) { + // // We render U+1F6E1 (🛡) with a width of 2, + // // but widechar_width says it has a width of 1 because Unicode classifies it as "neutral". + // // + // // So we simply decide the width ourselves + // if (wc == 0x1F6E1) return 2; + // + // Well terminals do show it as width 1 after all + + int width = widechar_wcwidth(wc); + + switch (width) { + case widechar_ambiguous: + case widechar_private_use: + return 1; + case widechar_widened_in_9: + // Our renderer supports Unicode 9 + return 2; + case widechar_nonprint: + case widechar_combining: + case widechar_unassigned: + case widechar_non_character: + return 0; + default: + // Use the width widechar_width gave us. + return width; + } +} |