ohmu
·
2026-10-15
1#include "common/wcwidth.h"
2#include "3rdparty/widecharwidth/widechar_width_c.h"
3
4int mk_wcwidth(uint32_t wc) {
5 // // We render U+1F6E1 (🛡) with a width of 2,
6 // // but widechar_width says it has a width of 1 because Unicode classifies it as "neutral".
7 // //
8 // // So we simply decide the width ourselves
9 // if (wc == 0x1F6E1) return 2;
10 //
11 // Well terminals do show it as width 1 after all
12
13 int width = widechar_wcwidth(wc);
14
15 switch (width) {
16 case widechar_ambiguous:
17 case widechar_private_use:
18 return 1;
19 case widechar_widened_in_9:
20 // Our renderer supports Unicode 9
21 return 2;
22 case widechar_nonprint:
23 case widechar_combining:
24 case widechar_unassigned:
25 case widechar_non_character:
26 return 0;
27 default:
28 // Use the width widechar_width gave us.
29 return width;
30 }
31}