You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by René Schwaiger, Jay, Chris Han, Zoe Tian, Ryota Kayanuma, Jean Regisser, Willem Sonke, Vinicius Lima and Philippe Rigovanov
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.constint variation_selector_16 = 0xFE0F;
if (wc == variation_selector_16) return1;
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.
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):
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).
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
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.
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?
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.
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.
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.
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.
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.
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?
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, sorrytput smcup
# print argument and then ask terminal to report the cursor positionprintf"%s%s"$argv[1] \e\[6n\;
# the response is as if user typed itread-l out -n5# exit alt screen mode, sorrytput rmcup
# cursor is in the column after the thing was renderedset-l width (math (string match -r'\[\d;(\d+)R'$out)[2] - 1)
printf"%d\n"$widthend
$ 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.
Activity
faho commentedon Jan 24, 2019
Check that, set $fish_emoji_width to 2, set $fish_ambiguous_width to whatever your terminal says - 2 for wide, 1 for narrow.
jerr0328 commentedon Jan 24, 2019
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.
faho commentedon Jan 24, 2019
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:
and indeed, copying that one gets me 2 codepoints in the terminal (as confirmed by
od -t x1zorstring length). The latter is a variation selector. Which applies to another codepoint to change it somehow.Which we already mention in our code:
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 | pbcopygives 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
wcwidththat 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.floam commentedon Jan 24, 2019
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.
jerr0328 commentedon Jan 24, 2019
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(printfto avoid the newline thrown in byecho) 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, thoughstring length 🛠shows a length of 1. Here's the output ofprintf \U1F6E0 | god -t x1z(prefix of g for gnu version, macOS otherwise has the BSD version which doesn't haveztype):I'm not really sure if this means anything...
faho commentedon Jan 25, 2019
It is for me, but that's probably due to me using firefox and/or linux. It's not all that important.
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)
floam commentedon Jan 25, 2019
It's as wide as two a's.
jerr0328 commentedon Jan 25, 2019
I see it as two, as well.

printf '%sx\n' aa \U1F6E0shows 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 twoxcharacters).faho commentedon Jan 25, 2019
So... I'm afraid your terminal is wrong.
jerr0328 commentedon Jan 25, 2019
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
floam commentedon Jan 25, 2019
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.
floam commentedon Jan 25, 2019
And no, it's not the case that the libc wcwidth does any better:

19 remaining items
Don't increase the width for variation selector 15.
floam commentedon Mar 13, 2019
It really seems like we do need something more clever that takes entire strings into account. It seems to me that
wcswidthcould theoretically do this but does not. I assume ICU can figure it out? What's there short of that?floam commentedon Mar 13, 2019
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.
faho commentedon Mar 13, 2019
Sorry, if the font changes things there's nothing we can do. E.g. non-monospace fonts are broken here.
floam commentedon Mar 13, 2019
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.
ridiculousfish commentedon Mar 24, 2019
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.
gnachman commentedon Mar 25, 2019
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.
mqudsi commentedon Mar 28, 2019
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.
floam commentedon Apr 5, 2019
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?
floam commentedon Apr 6, 2019
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:It uses the alternate screen only because I couldn't figure out how to make
read -snot echo any characters like bash's can (we print the asterisks/bullet points instead of changing modes), andstty -echodidn'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.
floam commentedon Apr 6, 2019
Or maybe it could be triggered by
fish_config.faho commentedon May 28, 2019
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".