Skip to content

Should wcswidth return Narrow (1) for Basic Emojis followed by VS-15, U+FE0E? #211

Closed

Description

@Jackenmen

Here's an example where it causes misalignment for me in Kitty terminal:
Image

The code:

import wcwidth
default = "\N{WHITE HEAVY CHECK MARK}"
text = "\N{WHITE HEAVY CHECK MARK}\N{VARIATION SELECTOR-15}"
emoji = "\N{WHITE HEAVY CHECK MARK}\N{VARIATION SELECTOR-16}"
variations = [default, text, emoji]
for v in variations:
    width = wcwidth.wcswidth(v)
    print(v, width)
    print(" " * width, "This should align with above?")

Activity

  1. changed the title [-]Should wcswidth return 2 for text-style of an emoji character?[/-] [+]Should wcswidth return 2 for text-style of an emoji character? (VS-15, U+FE0E[/+] on Mar 28, 2026
  2. jquast commented on Mar 28, 2026

    @jquast
    Owner

    Yes @Jackenmen, actually I do agree with Kovid Goyal's specification,

    U+FE0E - Variation Selector 15

    When the previous cell has width two and the last code point in the previous cell is one of the Basic_Emoji code points from the Wide emoji rule above that is not followed by U+FE0F then the width of the previous cell is decreased to one.

    I independently came to the same conclusion, my remarks from analysis last year

    And I think VS-15 serves to fulfill the need to display normally Wide emojis in a matching size and bitonal color, of only these select few early emojis, as if to show it in its historical or simplified form. I believe VS-15 exists for a mirrored property, that turning a Wide emoji into text display makes it Narrow (VS15), just as making text into emoji presentation makes it wide(VS16).

    This analysis was done in response to @j4james' criticism on HN,

    And at one time the East Asian Width spec specifically mentioned VS-16 making narrow characters wide (but said nothing about VS-15 making wide characters narrow).

    I asked @j4james to review, responding,

    Aside from the practicality, the fact that TR-11 was so explicit about the VS-16 making glyphs wider, while having no mention of VS-15 making glyphs narrow, is (I think) what convinced most terminal devs that VS-15 should only affect the visual appearance, and not the width.

    It's not like this topic hasn't been discussed before. It's just that almost everyone has already agreed on the correct behavior. That's why you're seeing the results you're seeing in your tests.

    And so the matter was closed and not published.

  3. changed the title [-]Should wcswidth return 2 for text-style of an emoji character? (VS-15, U+FE0E[/-] [+]Should wcswidth return Narrow for Basic Emojis followed by VS-15? (VS-15, U+FE0E[/+] on Mar 28, 2026
  4. jquast commented on Mar 28, 2026

    @jquast
    Owner

    I renamed your title to be more clear, please check, that:

    >>> wcwidth.wcswidth("\N{WHITE HEAVY CHECK MARK}\N{VARIATION SELECTOR-15}")
    2

    wcswidth() measures this as a "wide character" (2 cells), which matches a majority of terminals, but, in kitty, this is displayed as "narrow" (one cell).

    I do agree the correct interpretation of the specification should return 1 instead of 2, but python wcwidth as it is currently published returns 2.

    Happy to have any further feedback.

  5. changed the title [-]Should wcswidth return Narrow for Basic Emojis followed by VS-15? (VS-15, U+FE0E[/-] [+]Should wcswidth return Narrow (1) for Basic Emojis followed by VS-15? (VS-15, U+FE0E[/+] on Mar 28, 2026
  6. changed the title [-]Should wcswidth return Narrow (1) for Basic Emojis followed by VS-15? (VS-15, U+FE0E[/-] [+]Should wcswidth return Narrow (1) for Basic Emojis followed by VS-15, U+FE0E?[/+] on Mar 28, 2026
  7. Jackenmen commented on Mar 28, 2026

    @Jackenmen
    Author

    Yes, returned cell width for "\N{WHITE HEAVY CHECK MARK}\N{VARIATION SELECTOR-15}" is 2, not 1.
    I didn't realise that Kitty is alone in this interpretation, I thought it would be the more common one.

    I don't think there's really anything better to do in wcwidth then and this should just be closed.
    Thanks for a detailed response with all the references!

  8. jquast commented on Mar 28, 2026

    @jquast
    Owner

    Your welcome!

    Yes, Kovid and I may be wrong about the interpretation of the unicode.org standard.. it's not really our fault, the for-pay membership unicode technical committee makes little to no effort to specify any concern for fixed-width/monospace rules, so they leave a lot up for interpretation.

    In these cases, this library aims to be most compatible with a majority of "progressive" or "actively developed" terminals. kitty is certainly one of the best, ranking number 2 in ucs-detect results which includes matching the specification of python wcwidth, (after ghostty, number one, which also appears to agree to display these characters Narrow by my testing).

    But, they are also alone in this regard, only 2 out of 35 terminals tested match this behavior right now. note that my testing reads "python wcwidth.wcswidth() measures width 1, while [...] measures width 2.", but this statement is false, I need to update this documentation to reflect this specific "VS-15" automatic testing does not match current released python wcwidth behavior, it's tricky to describe because of this fence sitting.

    I have updated ucs-detect report to reference this issue,

    The interpretation of VS-15 (U+FE0E) narrowing Wide Emoji is contested. While this test expects VS-15 to make Wide Emoji Narrow, most terminal emulators do not implement this behavior, and python wcwidth.wcswidth() does not currently return a narrow width for these sequences. Only 2 of 35 terminals tested match this expectation. This score is excluded from the final ranking. See jquast/wcwidth#211.

    So I will leave this issue open, anyway. I can certainly be persuaded to match kitty and ghostty, as these terminal authors are very progressive and thoughtful about their implementation compared to the other terminal authors.

  9. reopened this on Mar 28, 2026
  10. jquast commented on Mar 28, 2026

    @jquast
    Owner

    An issue where @j4james persuaded @christianparpart against implementing VS-15/U+FE0E in Contour terminal, contour-terminal/contour#404 (comment)

  11. j4james commented on Mar 28, 2026

    @j4james

    If you think an emoji followed by VS-15 should have a width of 1, here's a little test for you to run.

    import sys
    check = '\u2705'
    check_vs15 = check+'\uFE0E'
    
    sys.stdout.write('<--------20-------->\n')
    
    sys.stdout.write('\033[4h')    # enable insert mode 
    sys.stdout.write('*'*10)       # write 10 asterisks
    sys.stdout.write('\r')         # return to start of line
    sys.stdout.write(check*5)      # insert 5 check marks
    sys.stdout.write('\n')         # move to new line
    sys.stdout.write('*'*10)       # write 10 asterisks
    sys.stdout.write('\r')         # return to start of line
    sys.stdout.write(check_vs15*5) # insert 5 check marks with VS-15
    sys.stdout.write('\n')         # move to new line
    sys.stdout.write('\033[4l')    # back to replace mode
    
    sys.stdout.write('<-----15------>\n')

    In the code above, we're writing out 10 asterisks, then inserting 5 emojis at the start of the same line using IRM. For the first attempt, the emojis have no VS-15 suffix, and in the second attempt, each emoji is followed by a VS-15 suffix.

    If VS-15 makes the emoji narrow, then the first line should span 20 columns, and the second line should only span 15 columns.

    Here's what it looks like in Ghostty:
    Image

    And here's what it looks like in Kitty:
    Image

    Make of that what you will.

  12. jquast commented on Mar 29, 2026

    @jquast
    Owner

    We mismatch on ghostty, versions 1.3.0-main+4b7a55a50 (Feb 26), and 1.3.2-main+4903e2821 (today) appear as:

    Image

    Which includes key VS-15 related PR's, ghostty-org/ghostty#9678 and ghostty-org/ghostty#9679 (Nov 24)

    As for IRM behavior, you are correct that you predicted this misbehaving insert mode with a wide-to-narrow VS-15, wcwidth so far does not interpret this sequence (and I don't think it should)

  13. j4james commented on Mar 29, 2026

    @j4james

    We mismatch on ghostty

    Yeah, I just came here to post an updated screenshot. My original test was on an older version. But the fundamental problem still remains. Neither of those terminals are consistently handling VS-15 characters as 1 cell wide, and any application assuming that is going to break.

  14. j4james commented on Mar 29, 2026

    @j4james

    Btw, here's another scenario for you. Imagine you're writing an editor, and you've determined that the terminal screen width is w, if wcswidth reports a string's width to be w, is it safe to assume you can fit that string on one line without wrapping?

    Test case:

    import struct, fcntl, termios
    winsz = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, struct.pack('HHHH', 0, 0, 0, 0))
    h,w,_,_ = struct.unpack('HHHH', winsz)
    
    check = '\u2705'
    check_vs15 = check+'\uFE0E'
    
    print('*' * w)
    print(check_vs15 * w)

    With a terminal width of 40, I can fit 40 asterisks on one line, so if a VS-15 check mark is also 1 cell wide, I should also be able to fit 40 check marks on one line, right?

    Here's Ghostty:
    Image

    And here's Kitty:
    Image

    Do you honestly still think that these are the only terminals that have got VS-15 right, and everyone else has got it wrong?

  15. 10 remaining items

  16. kovidgoyal commented on Mar 29, 2026

    @kovidgoyal
  17. kovidgoyal commented on Mar 29, 2026

    @kovidgoyal
  18. kovidgoyal commented on Mar 29, 2026

    @kovidgoyal

    As promised, here is a function that takes an iterator over graphemes
    and writes it to the terminal in no more than wcswidth() cells so that
    it does not suffer from an unpredictability of behavior. It uses only
    classic terminal escape codes to do it. As long as the code used to
    split into graphemes and the terminals code ot split into graphemes
    match, this is 100% deterministic when you use it to output text one
    screen line at a time. Of course, it's better to use the text sizing
    protocol, but this is a useful stopgap until that is more widely
    adopted.

    class Grapheme:
        text: str
        width: int = 1
    
    
    def output_in_wcswidth(iterator_over_graphemes):
        ' Output graphemes so that they affect exactly wcswidth cells only (works for >= 2 graphmes) '
        graphemes = tuple(iterator_over_graphemes)
        if not graphemes:
            return
        yield graphemes[0].text
        for i in range(1, len(graphemes)):
            g = graphemes[i]
            if g is graphemes[-1]:
                prev_g = graphemes[i-1]
                yield f'\x1b[{prev_g.width}D'  # move cursor back]
                yield g.text
                yield f'\x1b[{g.width}D'  # move cursor back]
                yield f'\x1b[{prev_g.width}@'  # insert cells]
                yield prev_g.text
                yield f'\x1b[{g.width}C'  # move cursor forward]
  19. kovidgoyal commented on Mar 29, 2026

    @kovidgoyal

    @j4james read http://www.unicode.org/reports/tr11/#ED5 East Asian "Narrow (Na): All other characters that are always narrow and have explicit fullwidth or wide counterparts. These characters are implicitly narrow in East Asian typography and legacy character sets because they have explicit fullwidth or wide counterparts. All of ASCII is an example of East Asian Narrow characters."

    Then in ED7: "ED7. Neutral (Not East Asian): All other characters. Neutral characters do not occur in legacy East Asian character sets. By extension, they also do not tend to occur in East Asian typography. For example, there is no traditional Japanese way of typesetting Devanagari. Canonical equivalents of narrow and neutral characters may not themselves be narrow or neutral respectively. For example, U+00C5 Å LATIN CAPITAL LETTER A WITH RING ABOVE is Neutral, but its decomposition starts with a Narrow character.

    Strictly speaking, it makes no sense to talk of narrow and wide for neutral characters, but because for all practical purposes they behave like Na, they are treated as narrow characters (the same as Na) under the recommendations below.

    In a broad sense, wide characters include W, F, and A (when in East Asian context), and narrow characters include N, Na, H, and A (when not in East Asian context)."

    And I have spent as much time on this as I care too. It's both patently obvious and in the standard above that text presentation characters should be narrow. And it is in the standard in UTS51 that VS15 changes the presentation to text from emoji when the base character has emoji presentation. It is as simple as that. Good luck. I am done repeating myself.

  20. kovidgoyal commented on Mar 29, 2026

    @kovidgoyal

    The TLDR: ED4 says Emoji_presentation characters have W class aka width 2. ED5 and ED7 say all Na and A codepoints have narrow width. ED4 is what makes emoji have W=2 when they have emoji presentation. Once an emoji is changed to text presentation, ED4 does not apply. Then ED5 and ED7 apply. Hence it has width=1

  21. mikeshardmind commented on Mar 29, 2026

    @mikeshardmind

    tr11 has the following to say:

    Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). If the context cannot be established reliably, they should be treated as narrow characters by default.

    none of ED4, ED5, or ED7 make those characters cease being classed as W when given text_presentation, they are still emoji_presentation characters, even when their text presentation has been requested by a following variation selector.

    If you want to say this is ambiguous or underspecified, then the next answer is to check the available context. In the case of a terminal with a font for rendering, this would obviously just be checking the font's width for that character in text presentation.

    This is something that probably should be cleared up more in the specification, but having the ability to give wcwidth the font currently in use to use for context would allow such situations to be inline with what users actually see rendered.

    With regard to the associated issue over on the terminal side, I don't think most apps have a good way to solve this (ask for the font and other context) with the current standards and protocols, but I'd love to be wrong about that.

  22. j4james commented on Mar 29, 2026

    @j4james

    I don't think most apps have a good way to solve this (ask for the font and other context) with the current standards and protocols, but I'd love to be wrong about that.

    @mikeshardmind This was the reason Contour proposed the terminal-unicode-core spec, and why it has a mode which applications can query to determine whether a particular terminal is following that spec. Regardless of how different people may interpret the wording of the Unicode standard, if a terminal reports that it is following the terminal-unicode-core spec, then apps should be able to rely on that terminal rendering a sequence of glyphs with a predictable width (at least in a perfect world in which nobody has any bugs).

  23. jquast commented on Mar 29, 2026

    @jquast
    Owner

    On Mode 2027

    I included DEC Private Mode 2027 in the results to accompany Mitchell's table from his article, Grapheme Clusters and Terminal Emulators, and to verify for myself that it has limited utility.

    In theory, a CLI program can query this mode to classify a terminal as "reasonably supporting" unicode, but not which specific features or version level. Since other terminals with similar capabilities do not respond to Mode 2027 queries, this binary indicator has limited utility.

    The only practical approach to determining Unicode support of a terminal is to interactively test for specific features, codepoints, and at the Unicode version levels of interest, as ucs-detect does.

  24. jquast commented on Jun 5, 2026

    @jquast
    Owner

    Next release of wcwidth.wcswidth() will return Narrow (1) for Basic Emojis followed by VS-15.

    This is because new function, wcstwidth() can be used to provide measurement corrections:

    >>> text_emoji = "\N{WHITE HEAVY CHECK MARK}\N{VARIATION SELECTOR-15}"
    >>> wcwidth.wcswidth(text_emoji)  # vs-15 is now narrow by default
    1
    >>> # get measurement with possible correction applied by process TERM_PROGRAM or TERM (ghostty)
    wcwidth.wcstwidth(text_emoji)
    1
    >>> # get "corrected" width for contour terminal,
    >>> wcwidth.wcstwidth(text_emoji, term_program='contour')
    2
  25. reopened this on Jul 22, 2026
  26. Repository owner locked and limited conversation to collaborators on Aug 12, 2026
  27. converted this issue into a discussion #234 on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions