Skip to content

Rendering issue with zero-width spaces #4571

Closed

Description

@jpillora
//zero-width space => 1
console.log("​".length);
//empty string => 0
console.log("".length);

Any command with a zero-width space causes future rendering issues when displaying the command from history:

#run zero-width space code with node => 1
node -p 'console.log("​".length);'
#echo zero-width space
echo "​"

Pasting this into bash will display the zero-width space as a normal space. However, pasting this into fish causes rendering issues whenever a command from history has a zero-width space (you don't actually have to run node to see the issue).

It was happening on fish 2.2/2.3. I updated to 2.7.0 and it's still occurring. Also tried without third-party extensions and still occurs.

jp $ fish --version
fish, version 2.7.0
jp $ uname -a
Darwin jp 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64
jp $ echo $TERM
xterm-256color

Activity

  1. faho commented on Dec 2, 2017

    @faho
    Member

    Fish uses a function called wcwidth to figure out how many cells a character uses. It ships its own version, and that returns "0" for a zero-width space, which seems correct.

    It's possible your terminal uses a different definition that returns something else, and so fish and the terminal get out of sync.

    Can you try #4554 (which would use the os-provided version which the terminal probably uses, so both would be wrong in the same way)? Can you try a different terminal (which might use a different wcwidth)?

  2. jpillora commented on Dec 8, 2017

    @jpillora
    Author

    "Can you try #4554" so you mean compile that C program and run it?

    iTerm2 is my main terminal and I just tested with macOS's Terminal.app, happens there too when I paste echo "​" into fish. Whereas works in bash:

    screen shot 2017-12-08 at 8 05 40 pm

  3. faho commented on Dec 8, 2017

    @faho
    Member

    "Can you try #4554" so you mean compile that C program and run it?

    The program I posted there would help, yes. It's also a PR that adds a commit to fish, so you could also try compiling and running that, but I don't think there should be a difference.

    works in bash

    And that's not all that surprising. The reason this causes problems in fish is that fish needs to do a bunch of cursor movement for suggestions and highlighting and such, and that needs to count the columns correctly, in the same way that the terminal does.

    However, looking at that screenshot, it seems like Terminal.app is wrong here. I'm assuming the argument to echo is just a zero-width space in quotes. It's displayed as one column of whitespace (i.e. the same as a normal space), which is wrong. So obviously that'll cause a difference between fish's column count and the terminal's.

    So the best we can expect here is that the terminal is using the system's wcwidth, and that switching to that will make fish and the terminal wrong in the same way, which should make for a better experience.

    compile that C program and run it?

    If you do, can you add L'\u200B' to chars[]?

  4. jpillora commented on Dec 26, 2017

    @jpillora
    Author

    Sorry for the delay:

    $ g++ widthtest.cpp
    widthtest.cpp:204:19: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
        for (wchar_t c: chars) {
                      ^
    1 warning generated.
    $ ./a.out
    Sys =  MK
     -1 =   1 : '﷽'
     -1 =   1 : '⚡'
      2 =   1 : '😃'
     -1 =   1 : '⸻'
      1 =   0 : '​'
    

    It displays here as zero-width, but when rendered in iTerm2, it looks like:

    screen shot 2017-12-26 at 3 06 03 pm

    Note: I added single-quotes the cpp program.

  5. faho commented on Dec 26, 2017

    @faho
    Member

    So, as you can see here, your system's version (which iTerm is probably using) is wrong in a few places. It's assigned a width of 1 to the zero-width space, and the high voltage sign has a width of -1. (The arabic one - the bismillah - as well, but everybody gets that one wrong)

    What I'd assume is that this is one of those cases where it's better for fish to be wrong in the same way as the terminal. Can you try building the fish from #4554?

    Note that the rendering is wrong regardless - you'll see how all of the other characters overlap the closing quote. There's nothing we can do to fix that.

    @ridiculousfish: This is what I was talking about in #4554. We get the zero-width space right and we're still worse off than bash.

  6. faho commented on Jan 4, 2018

    @faho
    Member

    Let's track this in #4539.

  7. ridiculousfish commented on Feb 26, 2018

    @ridiculousfish
    Member

    With 5282d3e this character U+200B should have its width "correctly" reported as 1. Please comment if you don't see this fixed - thanks!

  8. added a commit that references this issue on Mar 13, 2018
  9. added a commit that references this issue on Mar 25, 2018
  10. 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions