7 ms·
I spent quite a bit of time coming up with an algorithm that gives me the correct width for any Unicode character, including emojis [1]. The reality is much mor
by rivo 3y ago
I spent quite a bit of time coming up with an algorithm that gives me the correct width for any Unicode character, including emojis [1]. The reality is much more complicated than what wcwidth does and using the East Asian Width attribute will give wrong results, as outlined in the article.
Unfortunately, since a lot of terminals simply use wcwidth, you often have to use that same flawed algorithm in your application to make it work in those terminals.
[1] https://pkg.go.dev/github.com/rivo/uniseg#hdr-Monospace_Width https://pkg.go.dev/github.com/rivo/uniseg#hdr-Monospace_Widt...