Skip to content

Add emoji display width support to mk_wcwidth#114

Open
thaafox wants to merge 1 commit intoGothenburgBitFactory:masterfrom
thaafox:fix/emoji-display-width
Open

Add emoji display width support to mk_wcwidth#114
thaafox wants to merge 1 commit intoGothenburgBitFactory:masterfrom
thaafox:fix/emoji-display-width

Conversation

@thaafox
Copy link

@thaafox thaafox commented Mar 24, 2026

Summary

  • mk_wcwidth() now returns correct display widths for emoji pictographs (width 2), common symbols (width 1), and variation selectors (width 0)
  • New utf8_truncate_to_width() function for safe width-based string truncation that respects multi-byte character boundaries

Problem

Emoji codepoints U+1F300+ are not covered by the existing width tables, so mk_wcwidth() returns 0 for them. This causes column misalignment in table output when task descriptions contain emoji — affecting all platforms (Linux, macOS, Windows).

Changes

  • utf8.cpp: Add emoji/symbol/variation-selector width ranges to mk_wcwidth() fallback handling
  • utf8.cpp: Add utf8_truncate_to_width() — truncates by display columns instead of bytes/characters
  • utf8.h: Declare utf8_truncate_to_width()

Test plan

  • Verified emoji like 📄🔥🐛 report width 2
  • Verified symbols like ✓★⚡→● report width 1
  • Verified utf8_truncate_to_width() never splits multi-byte sequences

mk_wcwidth() returns 0 for emoji codepoints (U+1F300-U+1FAFF) because
they fall through as unassigned. Modern terminals render these as
2-cell-wide characters, causing column misalignment in any application
that relies on mk_wcwidth() for layout.

Add explicit width mappings:
- Emoji pictographs (U+1F300-U+1F9FF, U+1FA00-U+1FAFF): width 2
- Arrows, geometric shapes, dingbats, misc symbols: width 1
- Variation selectors (U+FE00-U+FE0F): width 0

Add utf8_truncate_to_width() which truncates a UTF-8 string to fit
within a target number of display columns, ensuring multi-byte
sequences are never split mid-character.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant