From a65a2f019e07835cdbaf31db7faa687b6c111201 Mon Sep 17 00:00:00 2001 From: Denys Dovhan Date: Thu, 18 Jan 2018 01:02:03 +0200 Subject: [PATCH] Allow spaceship:section arguments to contain escapes --- docs/API.md | 2 ++ lib/section.zsh | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/API.md b/docs/API.md index 5ed0d11e5..51c8fee30 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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. diff --git a/lib/section.zsh b/lib/section.zsh index a1f512b1a..f8b01d188 100644 --- a/lib/section.zsh +++ b/lib/section.zsh @@ -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