问题描述
我早些时候尝试制作自己的 Oh My Zsh 主题.一切都很好,除了当我在提示中输入长行(比下面看到的行长)时,该行消失了.但是,如果我调整窗口大小,该行会重新出现.
I had a go at making my own Oh My Zsh theme earlier. All is well, except when I type long lines in the prompt (any longer than the line seen below), the line disappears. The line re-appears if I resize the window, however.
我的主题中是否存在导致这种情况发生的原因?
Is there something in my theme that is causing this to happen?
如果我输入一个额外的字符然后删除一个,光标会出现在窗口的边缘.
If I type an additional character and then erase one, the cursor appears at the edge of the window.
您可以在此处查看主题代码.这是我认为我们关心的一点:
You can view the code for the theme here. Here’s the bit I think we are concerned with:
# Build the prompt
PROMPT='
' # Newline
PROMPT+='${style_user}%n' # Username
PROMPT+='${style_chars}@' # @
PROMPT+='${style_host}%m' # Host
PROMPT+='${style_chars}: ' # :
PROMPT+='${style_path}%c ' # Working directory
PROMPT+='$(git_custom_status)' # Git details
PROMPT+='
' # Newline
PROMPT+='${style_chars}\$${RESET} '
推荐答案
顺便说一句,您的链接已损坏,突出显示了发布代码链接而不是代码本身的问题之一 - 您问题的任何未来查看者都无法获得一张完整的图片.
Incidentally, your link is broken, highlighting one of the issues with posting a link to code instead of code itself - any future viewers of your question can't get a full picture.
我认为您的问题是您使用的颜色"字符应该在一对 %{...%}
:
I think your problem is that the 'color' characters you use should be escaped in a pair of %{...%}
:
%{...%}
Include a string as a literal escape sequence. The string within the braces
should not change the cursor position. Brace pairs can nest.
使用您最新的 在 github 上提交,我不没有看到这个问题 - 你解决了吗?但是,我发现光标放置和线条绘制存在一些问题,尤其是 TAB
.当按下TAB
时,光标上移一行:
Using your latest commit on github, I don't see this issue - did you fix it? However, I'm seeing some issues with cursor placement and line-drawing, particularly with TAB
. When pressing TAB
, the cursor is moved up one line:
在此处按下 .在此处按下 .
Pressed here.Pressed here.
PROMPT
每次都被重新绘制向上"一行.这是通过将颜色代码封装在 %{...%}
中来解决的:
The PROMPT
is being re-drawn 'up' one line every time. This is fixed by encapsulating the color codes within the %{...%}
:
# Solarized Dark colour scheme
BOLD="%{$(tput bold)%}"
RESET="%{$(tput sgr0)%}"
SOLAR_YELLOW="%{$(tput setaf 136)%}"
SOLAR_ORANGE="%{$(tput setaf 166)%}"
SOLAR_RED="%{$(tput setaf 124)%}"
SOLAR_MAGENTA="%{$(tput setaf 125)%}"
SOLAR_VIOLET="%{$(tput setaf 61)%}"
SOLAR_BLUE="%{$(tput setaf 33)%}"
SOLAR_CYAN="%{$(tput setaf 37)%}"
SOLAR_GREEN="%{$(tput setaf 64)%}"
SOLAR_WHITE="%{$(tput setaf 254)%}"
如果没有原始 ~/.zshrc
,我不能 100% 确定,但这应该会稍微改善您的提示.:)
I'm not 100% sure without the original ~/.zshrc
, but this should improve your prompt a little. :)
除了橙色之外,您还可以使用基于终端的 Solarized
配置文件和 zsh
colors
,可能 更便携.但是,如果没有 tput
,我就无法获得正确的橙色.
Apart from the orange, you can also use a terminal-based Solarized
profile and the zsh
colors
, which might be more portable. I couldn't get the orange right without tput
, though.
#autoload colors && colors
#SOLAR_YELLOW="%{$fg[yellow]%}"
#SOLAR_ORANGE="%{$(tput setaf 166)%}"
#SOLAR_RED="%{$fg[red]%}"
#SOLAR_MAGENTA="%{$fg[magenta]%}"
#SOLAR_VIOLET="%{$fg_bold[magenta]%}"
#SOLAR_BLUE="%{$fg[blue]%}"
#SOLAR_CYAN="%{$fg[cyan]%}"
#SOLAR_GREEN="%{$fg[green]%}"
#SOLAR_WHITE="%{$fg[white]%}"
这篇关于自定义 Oh My Zsh 主题:长提示消失/切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!