Skip to content

Commit

Permalink
Allow spaceship:section arguments to contain escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan committed Jan 17, 2018
1 parent 8b614dc commit a65a2f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ echo $SPACESHIP_ROOT
This command displays prompt section prefixed with `prefix`, suffixed with `suffix` and `content` painted in `color`. **Bold** style is applied by default.
`prefix`, `suffix` and `content` can contain escapes to set additinal foreground color, background color and other visual effects. Read more about escapes in [13 Prompt Expansion](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html) section of Zsh documentation.
If `SPACESHIP_PROMPT_PREFIXES_SHOW` is `false` or if the section is not the first in the prompt, then `prefix` will be omitted.
If `SPACESHIP_PROMPT_SUFFIXES_SHOW` is `false`, then `suffix` will be omitted.
Expand Down
18 changes: 9 additions & 9 deletions lib/section.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ spaceship::section() {

[[ -z $3 && -z $4 ]] && content=$2 prefix=''

echo -n "%{%B%}" # set bold
print -nP "%{%B%}" # set bold
if [[ $spaceship_prompt_opened == true ]] && [[ $SPACESHIP_PROMPT_PREFIXES_SHOW == true ]]; then
echo -n "$prefix"
print -nP "$prefix"
fi
spaceship_prompt_opened=true
echo -n "%{%b%}" # unset bold
print -nP "%{%b%}" # unset bold

echo -n "%{%B$color%}" # set color
echo -n "$content" # section content
echo -n "%{%b%f%}" # unset color
print -nP "%{%B$color%}" # set color
print -nP "$content" # section content
print -nP "%{%b%f%}" # unset color

echo -n "%{%B%}" # reset bold, if it was diabled before
print -nP "%{%B%}" # reset bold, if it was diabled before
if [[ $SPACESHIP_PROMPT_SUFFIXES_SHOW == true ]]; then
echo -n "$suffix"
print -nP "$suffix"
fi
echo -n "%{%b%}" # unset bold
print -nP "%{%b%}" # unset bold
}

# Compose whole prompt from sections
Expand Down

0 comments on commit a65a2f0

Please sign in to comment.