ZSH RPROMPT怪异的间距? [英] ZSH RPROMPT weird spacing?

查看:244
本文介绍了ZSH RPROMPT怪异的间距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ZSH提示主题

Here is my ZSH prompt 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'

看起来像

$(git_prompt_info)移至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)'

看起来像

看到右边的空格了吗?箭头也从错误的地方开始了吗?

See the spacing on the right? Also the arrow starts in the wrong place?

我该如何解决?

推荐答案

我相信$fg[color]包含类似\e[32m的内容?如果是这样,则必须将其括在%{…%}中以指示此序列没有宽度.但是更好的是,如果您忘记了整个过程,而将%F{color}用作前景,将%K{color}用作背景,并使用%f/%k代替$reset_color来取消它们.你必须做

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

setopt promptsubst
setopt promptpercent

为了使它起作用(您可能已经拥有了).

in order for this to work (you likely already do have this).

该间隙是颜色的宽度,它们是光标位置错误的原因.这里的问题是zsh无法查询终端问题,我输出了一些文本,它的宽度是多少?"而不是必须自己计算宽度.

That gap is the width of colors, and they are the reason why you have wrong cursor position. Problem here is that zsh can’t query terminal with the question "Hey, I outputted some text, what is its width?" instead having to calculate width on its own.

这篇关于ZSH RPROMPT怪异的间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆