问题
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} '
回答1:
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.
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:
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)%}"
I'm not 100% sure without the original ~/.zshrc
, but this should improve your prompt a little. :)
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]%}"
来源:https://stackoverflow.com/questions/13546672/custom-oh-my-zsh-theme-long-prompts-disappear-cut-off