Skip to content

Incorrect Width Calculation for Characters with Variation Selector-16 #274

@skiars

Description

@skiars

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

  1. Use the wctwidth function to calculate the width of the character 🏞️ (which is U+1F3DE followed by U+FE0F).
  2. 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:

Would be great to discuss potential fixes or workarounds for this issue. Thank you for your attention and support!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions