-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Description
I've noticed that the wctwidth
/ wcswidth
function in the vty
library seems to miscalculate the width of certain text, particularly those which involve the Variation Selector-16 (U+FE0F). For example, the emoji 🏞️
(National Park) is composed of U+1F3DE
followed by U+FE0F
. This should be rendered as a colorful double-width emoji. However, the current width calculation doesn't seem to reflect this correctly.
Steps to Reproduce
- Use the
wctwidth
function to calculate the width of the character🏞️
(which isU+1F3DE
followed byU+FE0F
). - Observe that the calculated width does not match the expected width (normally, it should be 2).
Example Code
ghci> import Graphics.Text.Width
ghci> wcswidth "🏞️" -- This should ideally return 2, but it doesn't
The wcswidth
function should return 2
for the character 🏞️
as it should be considered a double-width emoji. But the wcwidth
function currently returns 1
, which does not account for the Variation Selector-16 and results in incorrect rendering where the cursor position becomes misaligned in terminals.
Environment
- OS: ArchLinux
- Terminal: Konsole
- Vty Version: 6.2
Additional Context
Variation Selector-16 (U+FE0F) is used to indicate that the preceding character should be displayed as an emoji. Proper support for this selector is crucial for accurate width calculation of such Unicode sequences.
For reference, this issue has been observed with Windows Terminal too, and here is some relevant information:
- Unicode characters like
U+1F3DE
combined withU+FE0F
should be considered double-width. - Some more insights on Variant Selectors: https://unicode.org/reports/tr51/#def_vs
Would be great to discuss potential fixes or workarounds for this issue. Thank you for your attention and support!