Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backspacing over emojis causes them to be half erased #1012

Open
ElvenSpellmaker opened this issue Jun 15, 2020 · 22 comments
Open

Backspacing over emojis causes them to be half erased #1012

ElvenSpellmaker opened this issue Jun 15, 2020 · 22 comments

Comments

@ElvenSpellmaker
Copy link

Setting up Noto emoji using Emojis=noto in the config file (it doesn't allow me to select in the UI, it only ever shows None which might be another bug).

When entering emoji and then backspacing it only deletes half the emoji:
image

@mintty
Copy link
Owner

mintty commented Jun 15, 2020

The same happens with double-width CJK characters. The problem is that the shell's line editing features are not fully aware of non-single-width glyphs and position the cursor just one position back in this case.

@ElvenSpellmaker
Copy link
Author

ElvenSpellmaker commented Jun 15, 2020

I can backspace fine over a double width such as , is it some kind of broken mapping where the shell hasn't been updated to understand emojis?

@mintty
Copy link
Owner

mintty commented Jun 15, 2020

Ah right, this didn't work yet not too long ago. So maybe the shell uses out-of-date width information (a.k.a. locale).

@ElvenSpellmaker
Copy link
Author

The files referenced by this?

$ locale
LANG=en_GB.UTF-8
LC_CTYPE="en_GB.utf8"
LC_NUMERIC="en_GB.utf8"
LC_TIME="en_GB.utf8"
LC_COLLATE="en_GB.utf8"
LC_MONETARY="en_GB.utf8"
LC_MESSAGES="en_GB.utf8"
LC_ALL=en_GB.utf8

@mintty
Copy link
Owner

mintty commented Jun 15, 2020

For me, bash and mintty behave alike for characters 啕, ✅, 😀.
Which mintty version do you have and which character do you try?

@ElvenSpellmaker
Copy link
Author

3.1.8

啕 erases fine
✅ erases fine
😀 does it in two parts

@mintty
Copy link
Owner

mintty commented Jun 15, 2020

Forgot to ask which shell you use. Anyway, with bash I get this:
emoji-bs-0
and after 3s:
emoji-bs-1

@mintty
Copy link
Owner

mintty commented Jul 15, 2020

For the records:
Under the assumption that the shell assumes the smiley to be only 1 cell wide (as explained above), the screen shots show correct behaviour. Not a terminal issue.

@scandum
Copy link

scandum commented Aug 15, 2020

Is there a table somewhere with all the correct character widths?

Mintty has a multitude of issues with character width, but there's no point reporting them without knowing whether mintty is getting it wrong, the font is getting it wrong, or whether it's like the wild west and everyone does whatever they want.

@BrianInglis
Copy link

@mintty builds the project using tables from the latest Unicode releases which include recommended monospace character spacing for Asian and other glyphs, also takes into account text direction and other info, depending on locale and font settings.
You may see slightly different outputs depending on your locale settings (Asian/Western) and of course fonts.

@mintty
Copy link
Owner

mintty commented Aug 16, 2020

By default, mintty applies character width strictly following the "locale" set before starting mintty. Thus character width properties are determined by the system, not mintty. There is no multitude of mintty issues in this mode of operation, although the locale mechanism has its own issues, generic to all terminals. There is also no font dependency in default mode of operation.
Matters change with options Locale, Charset, Charwidth, PrintableControls, as well as with some escape sequences dynamically. See the manual page and the wiki page on control sequences. I will try to add a complete overview to the wiki Tips page.

@scandum
Copy link

scandum commented Aug 16, 2020

I had the impression indicwide.t is used, among other things, to determine width?

@mintty
Copy link
Owner

mintty commented Aug 16, 2020

Only if enabled by the respective escape sequence, see https://github.com/mintty/mintty/wiki/CtrlSeqs#wide-characters.

@scandum
Copy link

scandum commented Aug 17, 2020

Interesting, too bad it's not supported by xterm as well. Any hints as to how to pull the "locale" information for characters?

@ElvenSpellmaker
Copy link
Author

ElvenSpellmaker commented Jan 25, 2022

@mintty This backspace bug seems to be fixed, except now emojis are double width but count as single width when cursoring over them to the right, so you have to right arrow over them twice to get to the previous letter.

Also if you just have an emoji then the same applies to left arrow too. If you type a character mid-emoji you end up with a weird prompt:
image
EDIT: if you use back buffer it looks like this where the glyph has been split in two:
image

Also, the cursor flashes if you're over an emoji in the terminal.

Should I open two new bugs for these, or keep it all on this?

(My emoji is noto)

@mintty
Copy link
Owner

mintty commented Jan 25, 2022

To assess this issue and whether it's a bug at all (see comments above), please describe your environment:
which system version (uname -a), which shell and version (e.g. echo $BASH_VERSION) and which character you display.

@ElvenSpellmaker
Copy link
Author

ElvenSpellmaker commented Jan 28, 2022

$ uname -a
CYGWIN_NT-10.0 AML0147 3.3.3(0.341/5/3) 2021-12-03 16:35 x86_64 Cygwin

$ echo $BASH_VERSION
4.4.12(3)-release

Any emoji causes the above behaviour

@mintty
Copy link
Owner

mintty commented Jan 28, 2022

You must have configured something unusual or you must be doing something strange. Which you didn't describe, by the way, so a reproducible test case is missing. Look at this:
grafik
After one cursor-left:
grafik
After another cursor-left:
grafik
Back to the end, then Backspace:
grafik

@ElvenSpellmaker
Copy link
Author

ElvenSpellmaker commented Jan 28, 2022

EmojiBreak

You can see the right right arrow never goes past the emoji (it takes two presses to go over the emoji) and typing a letter ( in this case l) splits the emoji glyph in pieces.

If I now hit enter I get:

$  l▒
-bash: $'\360\237\215l\225': command not found

@ElvenSpellmaker
Copy link
Author

ElvenSpellmaker commented Jan 28, 2022

This one shows the other behaviour I mentioned whereby the emoji and cursor flashes violently while over an emoji:
EmojiFlashCursor

@mintty
Copy link
Owner

mintty commented Jan 28, 2022

Maybe we should also check your .inputrc and your locale, also your libreadline version.
If the interacting application does not handle double-width properly, as e.g. cat does, you can indeed navigate half-way into an emoji and typing a character will then split up the emoji. That's explained above and not a bug.
The cause of your shell behaving this old way is still mysterious.

@mintty
Copy link
Owner

mintty commented Jan 29, 2022

I wasn't sure about the precise key sequence that you're entering. This shows that exact descriptions are highly preferable over images or videos.
I can now in fact reproduce the issue above, when entering a smiley on the command line and navigating it like this:
🙂 Backspace x cursor-right y
with the following display
🙂 Backspace -> 🙂 highlighted
x -> x🙂, smiley highlighted
cursor-right -> x🙂, smiley highlighted (no change)
y -> x y�, � highlighted

When logging actual character output (e.g. mintty -l .log), final output is:
🙂^H^Hx🙂^H^H^[[Cy�
where ^H is a Backspace character, ^[ is an Escape character, ^[[C is the cursor-right terminal sequence, � is a 0x82 byte.
I don't know why shell interaction produces this sequence of output characters but as explained above, mintty rendering response to it is correct as the application places the cursor inside a double-width character and even outputs an illegal character code, both of which it should never do.
Things get much worse with emoji sequences but I'm not going to demonstrate that now. Not a mintty bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants