質問

I'm using ZSH with oh-my-zsh in Cygwin, and was using the "Cloud" theme, which put the Cloud emoji (☁) in front of the prompt. I liked that but wanted to try customizing it slightly to show a different image. However, some emoji characters (at least those I've tried) apparently will not render properly.

This is the cloud theme as it shipped with ohmyzsh:

if [[ -z $ZSH_THEME_CLOUD_PREFIX ]]; then
    ZSH_THEME_CLOUD_PREFIX='☁'
fi

PROMPT='%{$fg_bold[cyan]%}$ZSH_THEME_CLOUD_PREFIX %{$fg_bold[green]%}%p %{$fg[green]%}%c % {$fg_bold[cyan]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'

This is what it looks like with that theme:

ZSH terminal cloud theme screenshot

I tried swapping out the cloud emoji with another, as such:

if [[ -z $ZSH_THEME_PAW_PREFIX ]]; then
    ZSH_THEME_PAW_PREFIX='🐾'
fi

PROMPT='%{$fg_bold[yellow]%}$ZSH_THEME_PAW_PREFIX %{$fg_bold[green]%}%p %{$fg[green]%}%c %{$fg_bold[cyan]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'

However, it only shows half the emoji image in my console:

ZSH terminal paw theme screenshot

I will note that I'm using Source Code Pro monospace font in both instances. It looks to me like the emoji is being rendered in a narrower space in the second example. Is there a way I can fix this? Or rather, why would there be a difference? Is it something with how these emoji are encoded?

役に立ちましたか?

解決

This is not a zsh issue, it's a combination of problems with the terminal emulator and the character in question.

Here's the character used in my prompt:

enter image description here

I use a monospace font: Inconsolata. This means that all the characters line up vertically. However, the emoji character you're asking about is too wide (it takes up two character spaces).

I think this means that that character is typeset 1.7-2 times wider than a normal character, and your terminal emulator doesn't know how to handle it. When it's rendered, it displays the normal character width, unfortunately cutting off the right-hand portion of the character.

I would recommend:

  • Finding a different terminal emulator or font: I'm not sure whether it's your combination, or specifically the font, or specifically the emulator. (I don't use Cygwin, and can't recommend any Windows-based software).
  • Changing characters to one that doesn't overflow the character width.

Note: Interestingly, your first example is also too wide:

enter image description here

(it should be directly under the a). Perhaps it's just that the paw-print character is far too wide (double) instead of a little (1.5-ish).

You could try setting the character with a space after it:

ZSH_THEME_PAW_PREFIX='🐾 '

but I don't know if this will work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top