hyper icon indicating copy to clipboard operation
hyper copied to clipboard

A space before the cursor

Open tideman opened this issue 9 years ago • 14 comments

screenshot I am on the latest Hyper.app version I have searched the issues of this repo and believe that this is not a duplicate

OS version and name: macOS Sierra 10.12.2 Hyper.app version: 1.1.0

When my command prompt PS1 is loaded in Hyper it places one space before the cursor which leaves me confused when editing texts.

I tried editing the functions I use in my .bashrc to see if the space came from there but I didn't find it.

In my regular bashshell the extra space is not there.

This is the code I use to generate my PS1

` parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^]/d' -e 's/ (.*)/ (\1)/' }

parse_latest_commit() { git log -n 1 --pretty=format:"%H" }

ME_EMOJI=(🐶 🐱 🐭 🐹 🐰 🐸 🐯 🐨 🐻 🐷 🐮 🐵 🐼 🐙 🐧🐦🐤🍒🍈🍓😬😄😃😀☺️); RANDOM_ME_EMOJI=${ME_EMOJI[$((RANDOM%14))]};

export PS1="$RANDOM_ME_EMOJI \u \W [\033[32m]$(parse_git_branch)[\033[00m] => " `

tideman avatar Feb 14 '17 06:02 tideman

I thought it was maybe BLOCK vs BEAM or one of the plugins. But no luck fixing it. Seems like an "off by one" error someplace.

markkra avatar Feb 14 '17 17:02 markkra

I am experiencing the same issue when using tmux. Without tmux everything looks fine. macOS Sierra 10.12.3 zsh 5.3.1 + tmux 2.3 Hyper 1.1.0

andrei-zhidkov avatar Feb 15 '17 11:02 andrei-zhidkov

Have you tried removing the emoji from your prompt? I've noticed this happens only with certain emoji. Might be something to do with how many unicode characters certain emoji actually are? i.e. some only take one, others take two, which might be confusing hyper about how much space it should occupy.

mattdarveniza avatar Feb 16 '17 00:02 mattdarveniza

This actually happens to me as well, but only in tmux. Outside of a tmux session, everything aligns correctly.

seagoj avatar Feb 16 '17 02:02 seagoj

Broken here too on OSX, but only in tmux.

I've had this for many months.

flybayer avatar Feb 16 '17 03:02 flybayer

Broken for me too. I use the unicode 👻 "ghost in the shell" ps1 prompt. I work on web software localization so it's critical that my terminal fully support odd unicode characters.

In iterm it's fine, with or without tmux. In hyper with tmux there's 1 too little space and the 👻 overlaps the text. In hyper without tmux there's 1 too much space.

jakl avatar Feb 16 '17 22:02 jakl

This is almost certainly related to the emojis - more specifically, wherever the app is counting the number of characters that have been output, it's likely using String.length, which counts the number of bytes in the string instead of the number of symbols.

For example: '👻'.length returns 2, because the 👻 needs five hex digits to specify, (1F47B), which means that it takes two bytes in a Javascript string to store it.

Now, to fix it! In ES6, the simplest way is to use Array.from('👻').length instead.

I'd also consider adding punycode as a dependency, as this is unlikely to be the only issue we run into with Unicode character support.

lyndsysimon avatar Feb 17 '17 20:02 lyndsysimon

Thanks, I'll take a look. Not confident I'll find the best fix, but I'll work towards a pull request.

jakl avatar Feb 17 '17 20:02 jakl

I found relevant code. It looks like hyper calls hterm-umdjs's charWidth method. hterm just has a TODO for supporting emoji widths.

https://github.com/zeit/hyper/blob/master/lib/hterm.js#L67 https://github.com/dbkaplun/hterm-umdjs/blob/master/dist/index.js#L4839

jakl avatar Feb 17 '17 21:02 jakl

Great what you people found. Thanks a lot

tideman avatar Feb 20 '17 07:02 tideman

I also have an emoji in my PS1 and am experiencing this issue - see https://gist.github.com/sebm/7392d2db5205ee6bf6b402e47ff0047f

sebm avatar Feb 23 '17 18:02 sebm

FWIW I'm getting this in tmux in Hyper 1.3.1 with no custom emoji or character in my PS1. 😢

jdsimcoe avatar Mar 22 '17 21:03 jdsimcoe

Can confirm that removing the emoji removes the space. Peculiar!

deanputney avatar Mar 30 '17 04:03 deanputney

It's especially on emojis with several skin tones, because the information of the color needs some kind of extra space. Like explained from lyndsysimon above.

benny20832 avatar May 04 '18 08:05 benny20832