From 4e3ec4850cbadd7b744cb4110b4f17b3ab717949 Mon Sep 17 00:00:00 2001 From: romkatv Date: Tue, 28 May 2019 15:16:27 +0200 Subject: [PATCH] new feature: ruler above the prompt; to enable: POWERLEVEL9K_SHOW_RULER=true --- functions/icons.zsh | 5 +++++ powerlevel9k.zsh-theme | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index fdd01072..0a48f924 100755 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -30,6 +30,7 @@ function _p9k_init_icons() { # Set the right locale to protect special characters local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons=( + RULER_CHAR $'\u2500' # ─ LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace @@ -132,6 +133,7 @@ function _p9k_init_icons() { # Set the right locale to protect special characters local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons=( + RULER_CHAR $'\u2500' # ─ LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace @@ -239,6 +241,7 @@ function _p9k_init_icons() { fi icons=( + RULER_CHAR $'\u2500' # ─ LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace @@ -334,6 +337,7 @@ function _p9k_init_icons() { # Set the right locale to protect special characters local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons=( + RULER_CHAR $'\u2500' # ─ LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace @@ -432,6 +436,7 @@ function _p9k_init_icons() { # Set the right locale to protect special characters local LC_ALL="" LC_CTYPE="en_US.UTF-8" icons=( + RULER_CHAR $'\u2500' # ─ LEFT_SEGMENT_SEPARATOR $'\uE0B0' #  RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #  LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4e1bfb77..9d350fea 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -2202,6 +2202,7 @@ function _p9k_update_prompt() { typeset -gi _P9K_REGION_ACTIVE set_default POWERLEVEL9K_PROMPT_ADD_NEWLINE false +set_default POWERLEVEL9K_SHOW_RULER false powerlevel9k_refresh_prompt_inplace() { emulate -L zsh @@ -2439,6 +2440,34 @@ _p9k_init() { done _P9K_ALIGNED_RPROMPT+='$_P9K_RPROMPT' + if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then + repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} _P9K_LEFT_PREFIX+=$'\n' + fi + + if [[ $POWERLEVEL9K_SHOW_RULER == true ]]; then + _p9k_get_icon RULER_CHAR + local ruler_char=$_P9K_RETVAL + _p9k_prompt_length $ruler_char + if (( _P9K_RETVAL == 1 && $#ruler_char == 1 )); then + _p9k_color "" prompt_ruler BACKGROUND + _p9k_background $_P9K_RETVAL + _P9K_LEFT_PREFIX+=$_P9K_RETVAL + _p9k_color "" prompt_ruler FOREGROUND + _p9k_foreground $_P9K_RETVAL + _P9K_LEFT_PREFIX+=$_P9K_RETVAL + [[ $ruler_char == '.' ]] && local sep=',' || local sep='.' + local indent='${${ZLE_RPROMPT_INDENT:-1}/#-*/0}' + local ruler_len="\${\$((COLUMNS-$indent))/#-*/0}" + local pad_len="\$((COLUMNS-$ruler_len))" + _P9K_LEFT_PREFIX+="%b\${(pl$sep$ruler_len$sep$sep${(q)ruler_char}$sep)}%k%f" + _P9K_LEFT_PREFIX+="\${(l$sep$pad_len$sep$sep $sep)}" + fi + fi + + if [[ $ITERM_SHELL_INTEGRATION_INSTALLED == Yes ]]; then + _P9K_LEFT_PREFIX+="%{$(iterm2_prompt_mark)%}" + fi + _P9K_LEFT_PREFIX+='${${_P9K_BG::=NONE}+}${${_P9K_I::=0}+}' _P9K_RIGHT_PREFIX+='${${_P9K_BG::=NONE}+}${${_P9K_I::=0}+}' @@ -2471,14 +2500,6 @@ _p9k_init() { _P9K_LEFT_PREFIX+="%f%b%k" fi - if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then - repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} { _P9K_LEFT_PREFIX=$'\n'$_P9K_LEFT_PREFIX } - fi - - if [[ $ITERM_SHELL_INTEGRATION_INSTALLED == Yes ]]; then - _P9K_LEFT_PREFIX="%{$(iterm2_prompt_mark)%}$_P9K_LEFT_PREFIX" - fi - # If the terminal `LANG` is set to `C`, this theme will not work at all. if [[ $LANG == "C" && $POWERLEVEL9K_IGNORE_TERM_LANG == false ]]; then print -P "\t%F{red}WARNING!%f Your terminal's 'LANG' is set to 'C', which breaks this theme!"