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

emojis inside PS1 offset cursor by 1 #2587

Closed
aaronatmycujoo opened this issue Jan 11, 2018 · 21 comments
Closed

emojis inside PS1 offset cursor by 1 #2587

aaronatmycujoo opened this issue Jan 11, 2018 · 21 comments
Labels
👆 Is Upstream Issue is the fault of something Hyper uses and not Hyper itself 🐛 Type: Bug Issue pertains to something wrong within Hyper

Comments

@aaronatmycujoo
Copy link

aaronatmycujoo commented Jan 11, 2018

  • OS version and name: High Sierra 10.13.2 (17C88)
  • Hyper.app version: Hyper 1.4.8 (stable)

Issue

If I include an emoji inside PS1 my terminal cursor has an offset of 1.

export PS1="\w " # works
export PS1="\w 🐱" # issue

Any idea on what to do?

I took a screenshot to show the issue: https://imgur.com/a/Z2yxV

@albinekb
Copy link
Contributor

albinekb commented Jan 11, 2018

Add a space after the emoji, emojis are not monospaced so they can't fit inside a column. If you add a space as "padding" it will look correct 👍 @aaronatmycujoo

export PS1="\w 🐱 " # no probs

@aaronatmycujoo
Copy link
Author

aaronatmycujoo commented Jan 15, 2018

The problem is still there with the space. Maybe I didn't explain properly :, )

I made a video: https://streamable.com/sgqww

The space is in there, but it looks like it is being truncated. When I am in .bash_profile I am deleting the space between the emoji and the " and you can see the " going behind the cat.

@albinekb
Copy link
Contributor

I can't see the error there, maybe someone else can reproduce. Hyper handles emojis like iterm does for me, that's what I expect :)

@albinekb albinekb reopened this Jan 15, 2018
@aaronatmycujoo
Copy link
Author

aaronatmycujoo commented Jan 15, 2018

I use

- export PS1="\w - "
+ export PS1="\w 🐱 "

and here is my album to help demonstrate once again:

https://imgur.com/a/VsRJQ

@albinekb
Copy link
Contributor

Oh I see. Can you try running the latest code via our canary release? see https://zeit.co/blog/canary for more info. In there we have changed the terminal rendering lib to xterm which is better than hterm used in 1.x, it should be fixed there :) coming to stable ASAP. @aaronatmycujoo thanks for the info 👀

@aaronatmycujoo
Copy link
Author

aaronatmycujoo commented Jan 15, 2018

Hm that does not seem to help.

I do not think the problem is with your software? If I compare before and after:

https://imgur.com/a/DYySY

This is with an emoji and a space. The emoji seems to take up 2 columns and the cursor does not respects that, but the text does.

Maybe it has something to do with: https://www.youtube.com/watch?v=sTzp76JXsoY

@rikumi
Copy link

rikumi commented Jan 30, 2018

The problem is that Hyper treats all Unicode characters as half-width character, and forces them to fit in 8.4px width:

.unicode-node {
    display: inline-block;
    vertical-align: top;
    width: 8.4px;
}

Apart from emojis, this problem affects all CJK characters because they are full-width.

Additionally, when multiple CJK characters appear in sequence, one of the characters is repeated after the last by mistake. For example, paste あいうえお into Hyper, they may appear as あいうえおえ.

Also, typing in Hyper with CJK input methods will result in a total mess. Hyper will catch some of the letters into the terminal, prevent the input method bar from appearing, bring strange characters after the cursor, and turn the cursor into yellow. Here is an example with a Chinese input method typed ceshiceshiceshi. Hyper caught csiehcsi into the terminal, turned the cursor yellow, and brought some special glitch (maybe part of a character) right of the cursor.

Use one of the CJK input methods to reproduce the bug.

qq20180130-122832 2x

@aaronatmycujoo
Copy link
Author

Nice write up! So it is possible to detect halfwidth unicode characters and only force those to fit into the 8.4px width? Trying to help solve the problem here but I have no experience with this 😅

@rikumi
Copy link

rikumi commented Jan 30, 2018

@aaronatmycujoo

8.4px for half-widths; 16.8px for full-widths.
The font size can be customized, so this number may be generated. You may want to find the code that generated this number and that part of CSS.

Again, please also look into the other bugs I just mentioned apart from this one.

@rikumi
Copy link

rikumi commented Jan 31, 2018

There's an NPM package about this: is-fullwidth-code-point. Use this to solve the problem.

@curiouscrusher
Copy link

As a halfway hack for my setup I just added a width: auto !important to the unicode class.
It's not a great fix, and some emoji still seem to make the terminal rendering a bit funky until you run the command or clear the window.

I seem to have the most issues when using a 🐛 emoji, see the gif below for the odd rendering that occurs when you paste one in. The irony of a bug emoji causing a bug...

// custom css to embed in the terminal window
    termCSS: '.unicode-node {width: auto !important;}',

bug-emoji

@Stanzilla
Copy link
Collaborator

Hey there, please try again with the new Hyper v2 release and open a new issue if the problem stills exists. Thank you!

@Elderry
Copy link

Elderry commented Apr 23, 2018

I'm afraid that this issue remains in the 2.0 version, at least for the powerline character :
OS version: Windows 10 Pro Build 16299.371

Before input anything:
before

After input abc:
after

@Stanzilla Stanzilla reopened this Apr 23, 2018
@Stanzilla
Copy link
Collaborator

Thanks for reporting bag!

@Stanzilla Stanzilla added 🐛 Type: Bug Issue pertains to something wrong within Hyper and removed 🏚 Hterm bug labels Apr 23, 2018
@Stanzilla
Copy link
Collaborator

@Elderry that looks like xtermjs/xterm.js#1059, right?

@Stanzilla Stanzilla added the 👆 Is Upstream Issue is the fault of something Hyper uses and not Hyper itself label Apr 23, 2018
@Elderry
Copy link

Elderry commented Apr 24, 2018

@Stanzilla Nope, I don't think they are the same issue. But I can confirm this problem also happens in vscode, so it's fine to mark this as an upstream issue.

@rikumi
Copy link

rikumi commented Apr 25, 2018

Seems like in Hyper v2 the terminal is rendered in a canvas instead of with CSS. The problem with CJK characters has been fixed.

@youngboy
Copy link

youngboy commented Oct 28, 2018

About emoji unicode version and its width problem,
after xtermjs/xterm.js#1714 merge, this issue will be fixed

tested successful in my local build...
https://github.com/youngboy/hyper/releases/tag/2.1.0-canary.3

@aaronatmycujoo
Copy link
Author

For me the issue has been sovled with 2.1.0-canary.3 🎉

@LabhanshAgrawal
Copy link
Collaborator

Fixed in #4679

@bitttttten
Copy link

bitttttten commented Oct 7, 2020

I am still hitting this isse in Hyper 3.0.2 on stable and on canary.

PROMPT='%F{yellow}%/ 👻 %f'

Notice the space after the ghost. It appears in hyper like so:

Screenshot 2020-10-07 at 12 42 51

You can see the ghost is taking up two character spaces. If I replace the ghost with a letter, like A you'll get:

Screenshot 2020-10-07 at 12 43 35

To compare, this is what it looks like in my IDE. Ghost+space+"clear" against "A"+space+"clear".

Screenshot 2020-10-07 at 12 49 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👆 Is Upstream Issue is the fault of something Hyper uses and not Hyper itself 🐛 Type: Bug Issue pertains to something wrong within Hyper
Projects
None yet
Development

No branches or pull requests

9 participants