Skip to content

OS X High Sierra: unicode in fish_prompt gets wrong length calculated #4539

Closed

Description

@paulswartz

fish version: 2.6.0 and fa57565
OS: OS X High Sierra, 10.13.1

After upgrading, having a unicode character in my prompt (along with a right prompt) has the size calculated incorrectly.

screenshot 2017-11-15 15 29 48

In the above screenshot, everything is normal when I have a fully ASCII prompt. When I source my fish_prompt to re-add the Unicode character, the cursor is positioned on the next line.

Everything was working normally before the update to High Sierra. It's not working in either iTerm or Terminal.

Happy to get any other debugging information.

Activity

  1. anordal commented on Nov 16, 2017

    @anordal
    Contributor

    Is that a double width character? Which codepoint(s) is it?

  2. paulswartz commented on Nov 17, 2017

    @paulswartz
    Author

    It's🍺 'BEER MUG' (U+1F37A)

  3. anordal commented on Nov 17, 2017

    @anordal
    Contributor

    It looks as if fish doesn't account for character width when calculating the placement of the right prompt: Single-width characters are okay (even multi-codepoint characters are accounted for), yet for each beer, the right prompt gets shifted one more character onto the next line.

    function fish_prompt
        set beer (printf '\xF0\x9F\x8d\xba')
        printf '%s' $beer$beer$beer
    end
    function fish_right_prompt
        echo 0987654321
    end
    

    I'm able to reproduce in all terminals I have handy: xterm, gnome-terminal and weston-terminal.

  4. ridiculousfish commented on Nov 27, 2017

    @ridiculousfish
    Member

    Probably fish_wcwidth needs to be updated for emoji.

  5. added this to the fish-future milestone on Nov 27, 2017
  6. added
    bug
    on Nov 27, 2017
  7. faho commented on Nov 27, 2017

    @faho
    Member

    This works for me if I set HAVE_BROKEN_WCWIDTH to 0, i.e. rely on the OSs wcwidth. Maybe it's time to start relying on that again? It seems like the situation has improved dramatically.

  8. floam commented on Nov 27, 2017

    @floam
    Member

    I agree, it seems now we are the ones with the lousy implementation. 🤕

  9. wcandillon commented on Dec 13, 2017

    @wcandillon

    I'm having the same issue. For instance if I use an emoji in my git commit message, everything gets broken.

  10. faho commented on Dec 13, 2017

    @faho
    Member

    @wcandillon: Which emoji are you using? Can you try #4554?

  11. rrrnld commented on Jan 3, 2018

    @rrrnld

    I'm facing the same issue, described in some greater detail here because I thought it had to do with my theme.

    I pulled @faho's changes, built it (which worked after installing doxygen manually) and the error seems to be fixed:

    screen shot 2018-01-03 at 18 39 37

    Nice!

  12. added 3 commits that reference this issue on Feb 26, 2018
    6cdc559
    e93b123
    5282d3e
  13. ridiculousfish commented on Feb 26, 2018

    @ridiculousfish
    Member

    This should be fixed in 5282d3e . Note that wcwidth isn't sufficient since Terminal and iTerm2 measure emojis differently, and even iTerm 2 allows this to be controlled with a preference. fish tries to guess the right emoji size, but this can be set by the user via fish_emoji_width in case fish guesses wrong.

    Thanks for filing, please comment if you still see a problem. We can update the heuristic for any emulators that use width-2 emoji.

  14. modified the milestones: fish-future, on Feb 26, 2018
  15. added a commit that references this issue on Mar 13, 2018
  16. added a commit that references this issue on Mar 25, 2018
  17. ronjouch commented on Apr 23, 2018

    @ronjouch

    This should be fixed in 5282d3e . Note that wcwidth isn't sufficient since Terminal and iTerm2 measure emojis differently, and even iTerm 2 allows this to be controlled with a preference. fish tries to guess the right emoji size, but this can be set by the user via fish_emoji_width in case fish guesses wrong.

    Thanks for filing, please comment if you still see a problem. We can update the heuristic for any emulators that use width-2 emoji.

    @ridiculousfish reporting on latest master fish-2.7.1-1096-ga9e9af5c under GNOME Terminal 3.28.1 using VTE 0.52.1 under Arch Linux. Emojis behave bad by default, setting fish_emoji_width to 2 fixes the issue (see mandatory GIF below).

    Can you update the heuristic? Looking at 5282d3e, here's what I found in env that could make sense to detect GNOME Terminal:

     ~ env | grep -i terminal
    GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/ad34ec9c_8ebb_4e2e_97f3_7b73d053f526
    GNOME_TERMINAL_SERVICE=:1.765
    
     ~ echo $VTE_VERSION
    5201

    Thanks for fish! 🙂

    fish-emoji-width-2-gnometerminal

  18. ridiculousfish commented on Apr 24, 2018

    @ridiculousfish
    Member

    Ugh, my Ubuntu 16.04 with gnome-terminal has 1-width emojis. I guess this depends on something else. Let me try to report the 2-width case.

  19. jyn514 commented on Oct 22, 2019

    @jyn514

    I have the same issue with '▶️ ' in my prompt. It should be 1, it seems to be 2.

  20. faho commented on Oct 22, 2019

    @faho
    Member

    @jyn514 The solution is always the same:

    • Upgrade fish to >= 3.0.2
    • Set $fish_emoji_width to 2 if your system does Unicode >= 9 (most likely yes)
    • Set $fish_ambiguous_width to whatever width your terminal shows ambiguous characters at (in this case 2)
    • Don't use ambiguous characters of differing widths as that's not expressable.

    In this case this character is of ambiguous width so do set -g fish_ambiguous_width 2 (after upgrading to fish 3 if necessary), or set your terminal to show ambiguous characters as narrow instead of as wide.


    In future please open a new issue or come to https://gitter.im/fish-shell/fish-shell. This issue is old, closed and doesn't really apply to the specific question.

  21. locked as resolved and limited conversation to collaborators on Apr 16, 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