Skip to content

Emoji issues in Fish 3.0 #5583

Closed
Closed

Description

@jerr0328

Fish version: 3.0.0
macOS Mojave: 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64
iTerm2 Build 3.2.7, "Use Unicode 9 widths" unchecked
Ran without customizations (sh -c 'env HOME=$(mktemp -d) fish')
Asciinema: https://asciinema.org/a/O8w4MnrYyj95MHQlXrtbdZatm

Emojis are still causing issues. #2652 claims this issue is fixed, but different combinations of fish_emoji_width (none, 1, 2) seem to affect the behavior without really fixing the problem. In Fish 2.7 I seemed to have avoided the problem with the iTerm workaround, but after updating to Fish 3.0, it started breaking. I can set the emoji width to 1 or 2, but it only works on some emojis (e.g. with 🛠and 🐛, one breaks and the other is ok when setting the value to 1, and the breakage swaps when I change the value). Using a newer emoji (e.g. 🥳) also causes a lot of issues. I have tried as well the ambiguous width values, but it also seems to cause the same random issue.

I installed Fish via brew.

Activity

  1. faho commented on Jan 24, 2019

    @faho
    Member

    "Use Unicode 9 widths" unchecked

    Check that, set $fish_emoji_width to 2, set $fish_ambiguous_width to whatever your terminal says - 2 for wide, 1 for narrow.

  2. jerr0328 commented on Jan 24, 2019

    @jerr0328
    ContributorAuthor

    With those settings: https://asciinema.org/a/wq8gSqYoe0TIovNHPjRMJUfvR?t=20
    I also tried with both 2 and 1 for ambiguous width, did not help with the 🛠 character at all.

  3. faho commented on Jan 24, 2019

    @faho
    Member

    Soo.. I'm not sure if you noticed or it its the same for you, but your 🛠️ "character" doesn't show as a character here. It shows as an image. So I can't copy it to figure out which character it is. Googling "hammer and wrench emoji" sends me to https://emojipedia.org/hammer-and-wrench/, which explains that it is:

    Codepoints
    🛠 U+1F6E0
    ️ U+FE0F

    and indeed, copying that one gets me 2 codepoints in the terminal (as confirmed by od -t x1z or string length). The latter is a variation selector. Which applies to another codepoint to change it somehow.

    Which we already mention in our code:

        // Check for VS16 which selects emoji presentation. This "promotes" a character like U+2764
        // (width 1) to an emoji (probably width 2). So treat it as width 1 so the sums work. See #2652.
        const int variation_selector_16 = 0xFE0F;
        if (wc == variation_selector_16) return 1;

    So together with U+2764, a U+FE0F variation selector "upgrades" it to an emoji. So both together have a width of 2. The former separately has a width of 1, so we give U+FE0F a width of 1 as well.

    Now this hammer_and_wrench thingy (🛠) together with U+FE0F forms 🛠️. Which on my system looks absolutely identical. Not just the same width, the same actual symbol.

    So there's no change in width. So the U+FE0F would in this case have to have a width of 0.


    So, the easiest thing for you to do is to just use a different character. Maybe echo \U1F6E0 | pbcopy gives you a hammer_and_wrench without the variation selector that just works.

    What we should do, I have no clue. That bit above was from our version of a function called wcwidth that has this quaint notion that characters are independent and have a certain width. So it's called with just one character (well, "codepoint" would probably be the correct term here), without any context.

  4. floam commented on Jan 24, 2019

    @floam
    Member

    I was able to copy and paste 🛠 just fine from his comment, it's not an image. It does mess up fish's rendering with correctly-configured emoji widths.

  5. added
    bug
    and removed on Jan 24, 2019
  6. jerr0328 commented on Jan 24, 2019

    @jerr0328
    ContributorAuthor

    Interesting, that shows as a perfectly normal character to me here in Chrome, I don't know if the browser or Github is trying to render as an image, I see the character itself both in my comment and in yours.

    Running the printf \U1F6E0 | pbcopy (printf to avoid the newline thrown in by echo) doesn't help too much, I get the character but there's still some weirdness (like going up in the history and editing the command). I can work around this character, knowing that the codepoint is problem. For both, though string length 🛠 shows a length of 1. Here's the output of printf \U1F6E0 | god -t x1z (prefix of g for gnu version, macOS otherwise has the BSD version which doesn't have z type):

    0000000 f0 9f 9b a0                                      >�..�<
    0000004
    

    I'm not really sure if this means anything...

  7. faho commented on Jan 25, 2019

    @faho
    Member

    I was able to copy and paste hammer_and_wrench just fine from his comment, it's not an image.

    It is for me, but that's probably due to me using firefox and/or linux. It's not all that important.

    It does mess up fish's rendering with correctly-configured emoji widths.

    How wide is it?

    If you do printf '%s\n' aa \U1F6E0, is it as wide as one or two a?

    Because our wcwidth says it's one of those that changed in Unicode 9, so if you're using Unicode 9 widths, it should be as wide as 2 a.

    (And it's probably good news that it wasn't the variation selector)

  8. floam commented on Jan 25, 2019

    @floam
    Member

    It's as wide as two a's.

  9. jerr0328 commented on Jan 25, 2019

    @jerr0328
    ContributorAuthor

    I see it as two, as well.
    printf '%sx\n' aa \U1F6E0 shows that it's being treated as 1 wide, with the x on the second line in the second line (first line it's on the third, following the two x characters).
    screenshot 2019-01-25 at 18 19 52

  10. faho commented on Jan 25, 2019

    @faho
    Member

    So... I'm afraid your terminal is wrong.

  11. jerr0328 commented on Jan 25, 2019

    @jerr0328
    ContributorAuthor

    I saw the same behavior (with the printf) in the standard macOS Terminal as well, with different fonts as well. It could be a system-wide issue. I'm not sure how Vim handles it because I see it rendered correctly there

  12. floam commented on Jan 25, 2019

    @floam
    Member

    Yes, I should have said that I'm on macOS 10.14, Terminal.app and iTerm. If we can figure out the range of emojis rendering like this we should be able to add a special case to our wcwidth.

  13. floam commented on Jan 25, 2019

    @floam
    Member

    And no, it's not the case that the libc wcwidth does any better:
    wcwidth

  14. 19 remaining items

  15. floam commented on Mar 13, 2019

    @floam
    Member

    It really seems like we do need something more clever that takes entire strings into account. It seems to me that wcswidth could theoretically do this but does not. I assume ICU can figure it out? What's there short of that?

  16. floam commented on Mar 13, 2019

    @floam
    Member

    This is leaving aside that it seems like you actually need insight into the fonts available to figure out some things. But one could get much closer with a function given an entire string.

  17. faho commented on Mar 13, 2019

    @faho
    Member

    This is leaving aside that it seems like you actually need insight into the fonts available to figure out some things.

    Sorry, if the font changes things there's nothing we can do. E.g. non-monospace fonts are broken here.

  18. floam commented on Mar 13, 2019

    @floam
    Member

    Of course. Or if you don't have a graphical representation available for the slightly smiling emoji. Point is, a wcswidth taking into account which sequences come after other sequences, it seems like we could get closer to the right answer more of the time.

  19. ridiculousfish commented on Mar 24, 2019

    @ridiculousfish
    Member

    We're completely at the mercy of the terminal's rendering here. bash doesn't have these issues because bash doesn't care: it doesn't need to worry about character widths because it doesn't attempt to do layout. The price of this is that it can't support e.g. a right prompt. However I wonder if we can move fish towards caring less; if fish required the character width less often, it would help reduce this sort of issue.

  20. gnachman commented on Mar 25, 2019

    @gnachman

    Bash has lots of problems with character width because it likes to redraw the prompt under various circumstances, such as when you control-R or the window resizes. It's a fairly frequent source of bug reports for iTerm2.

  21. mqudsi commented on Mar 28, 2019

    @mqudsi
    Contributor

    Lol. I can sympathize. It feels like I spend most of my free time filing bug reports related to various resizing and and repainting issues in neovim where one patch fixes things for a terminal only to break it for ten others.

    What we need is a unified API in the opposite direction where a program can ask the terminal "tell me about the currently visible layout" (or "tell me how this changeset would be rendered") and get meaningful results back. There are too many variables beyond our control in 2019 that were simply not an issue in the 80s (let alone earlier). It's not just the number of bytes not correlating to the number of glyphs or the width of a glyph not being a single cell, even accounting for the same combination of terminal and shell. The font in use, the operating systems rendering features, accessibility options at play.. there has to be a better option than throwing it all away and bundling a web browser in a gtk toolkit and calling it a terminal that solves these problems.

  22. floam commented on Apr 5, 2019

    @floam
    Member

    The primary thing that would be nice to make better is the way the computed cursor position being off really makes things go to hell interactively in fish, it can make it hard to even enter commands because the user has to guess where fish is going to insert a character when they type, and guess what character will go away when they hit backspace. The stair stepping, text getting entered wrong, and way you start typing over the printed prompt is bonkers for a user to figure out. Could we do anything to cause fish not to care about the computed cursor position quite so much or limit the damage?

    A right prompt being misaligned is annoying but what's really maddening is an emoji appearing in your current command-line or being flashed from an autosuggestion and totally corrupting the experience. Could cursor position save/restores or querying the cursor position on capable terminals help?

  23. floam commented on Apr 6, 2019

    @floam
    Member

    I wrote this function to determine the actual rendered widths of given strings. It'll give the number of columns a character actually took after being printed out by the actual terminal regardless of wcwidth. It's been useful for testing things:

    function realwidth
        # enter alt screen mode, sorry
        tput smcup
        # print argument and then ask terminal to report the cursor position
        printf "%s%s" $argv[1] \e\[6n\;
        # the response is as if user typed it
        read -l out -n5
        # exit alt screen mode, sorry
        tput rmcup
        # cursor is in the column after the thing was rendered
        set -l width (math (string match -r '\[\d;(\d+)R' $out)[2] - 1)
        printf "%d\n" $width
    end
    $ realwidth 😳
    2
    

    It uses the alternate screen only because I couldn't figure out how to make read -s not echo any characters like bash's can (we print the asterisks/bullet points instead of changing modes), and stty -echo didn't work in fish.

    If this could be done without the alternate screen hacks and by diffing the before and after row/column addresses, in c++, it seems like we could do one-off checks on launch or first launch (in likeness to how we generate manpage completions) to determine the correct emoji width value and ambiguous width value, for capable terminals. Without the alternate screen junk/tput commands it takes 4ms in fish script currently to test 1 string.

  24. floam commented on Apr 6, 2019

    @floam
    Member

    Or maybe it could be triggered by fish_config.

  25. faho commented on May 28, 2019

    @faho
    Member

    I think the current situation is the best we can do with changes just in fish, so I'll close this.

    It's also not that bad anymore - use an up-to-date terminal on an up-to-date system and it should mostly "just work".

  26. added this to the fish 3.1.0 milestone on May 28, 2019
  27. locked as resolved and limited conversation to collaborators on Apr 17, 2020
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions