Add emoji display width support to mk_wcwidth#114
Open
thaafox wants to merge 1 commit intoGothenburgBitFactory:masterfrom
Open
Add emoji display width support to mk_wcwidth#114thaafox wants to merge 1 commit intoGothenburgBitFactory:masterfrom
thaafox wants to merge 1 commit intoGothenburgBitFactory:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mk_wcwidth()now returns correct display widths for emoji pictographs (width 2), common symbols (width 1), and variation selectors (width 0)utf8_truncate_to_width()function for safe width-based string truncation that respects multi-byte character boundariesProblem
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 tomk_wcwidth()fallback handlingutf8.cpp: Addutf8_truncate_to_width()— truncates by display columns instead of bytes/charactersutf8.h: Declareutf8_truncate_to_width()Test plan
utf8_truncate_to_width()never splits multi-byte sequences