ZSH RPROMPT weird space?

Here is my invited ZSH theme

function git_prompt_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX" } PROMPT='$fg[yellow]%}⚡︎ $fg[cyan]%~ $(git_prompt_info) %{$reset_color%}→ ' ZSH_THEME_GIT_PROMPT_PREFIX="[git:" ZSH_THEME_GIT_PROMPT_SUFFIX="]$reset_color" ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]+" ZSH_THEME_GIT_PROMPT_CLEAN="$fg[green]" RPROMPT='%T' 

It looks like

When I move $ (git_prompt_info) to RPROMPT

 function git_prompt_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX" } PROMPT='%T $fg[yellow]%}⚡︎ $fg[cyan]%~ %{$reset_color%}→ ' ZSH_THEME_GIT_PROMPT_PREFIX="[git:" ZSH_THEME_GIT_PROMPT_SUFFIX="]$reset_color" ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]+" ZSH_THEME_GIT_PROMPT_CLEAN="$fg[green]" RPROMPT='$(git_prompt_info)' 

it looks like this: enter image description here

See distance to the right. Also does the arrow start in the wrong place?

How can i fix this?

thanks

+6
source share
1 answer

I believe $fg[color] contains something like \e[32m ? If so, it should be enclosed in %{…%} to indicate that this sequence has no width. But it is much better if you forget about all this and use %F{color} for the foreground, %K{color} for the background and %f / %k to cancel them instead of $reset_color . You have to do

 setopt promptsubst setopt promptpercent 

for this to work (you probably already have this).

This space is the width of the colors, and they cause the cursor to go wrong. The problem here is that the zsh cant query terminal with the question "Hey, did I get some text, what is its width?" instead, you need to calculate the width yourself.

+9
source

All Articles