From 2feac7f121ce14be87d60f5deece441aef9f4583 Mon Sep 17 00:00:00 2001 From: romkatv Date: Mon, 20 Jan 2020 09:57:03 +0100 Subject: [PATCH 1/2] survive SIGINT during preexec; see #427 --- internal/p10k.zsh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 5a4e698f..0b7bf831 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3771,7 +3771,9 @@ function instant_prompt_direnv() { fi } -_p9k_preexec() { +# Use two preexec hooks to survive https://github.com/MichaelAquilina/zsh-you-should-use with +# YSU_HARDCORE=1. See https://github.com/romkatv/powerlevel10k/issues/427. +_p9k_preexec1() { if (( $+_p9k_real_zle_rprompt_indent )); then if [[ -n $_p9k_real_zle_rprompt_indent ]]; then ZLE_RPROMPT_INDENT=$_p9k_real_zle_rprompt_indent @@ -3780,6 +3782,10 @@ _p9k_preexec() { fi unset _p9k_real_zle_rprompt_indent fi + (( $+functions[TRAPINT] )) || trap - INT +} + +_p9k_preexec2() { _p9k__preexec_cmd=$2 _p9k__timer_start=EPOCHREALTIME } @@ -4658,8 +4664,7 @@ _p9k_precmd_impl() { _p9k__timer_start=0 _p9k__region_active=0 - unset _p9k__line_finished - unset _p9k__preexec_cmd + unset _p9k__line_finished _p9k__preexec_cmd _p9k__keymap=main _p9k__zle_state=insert @@ -4670,11 +4675,17 @@ _p9k_precmd_impl() { _p9k_set_prompt _p9k_refresh_reason='' + if [[ $precmd_functions[1] != _p9k_do_nothing && $precmd_functions[(I)_p9k_do_nothing] != 0 ]]; then + precmd_functions=(_p9k_do_nothing ${(@)precmd_functions:#_p9k_do_nothing}) + fi if [[ $precmd_functions[-1] != _p9k_precmd && $precmd_functions[(I)_p9k_precmd] != 0 ]]; then precmd_functions=(${(@)precmd_functions:#_p9k_precmd} _p9k_precmd) fi - if [[ $precmd_functions[1] != _p9k_do_nothing && $precmd_functions[(I)_p9k_do_nothing] != 0 ]]; then - precmd_functions=(_p9k_do_nothing ${(@)precmd_functions:#_p9k_do_nothing}) + if [[ $preexec_functions[1] != _p9k_preexec1 && $preexec_functions[(I)_p9k_preexec1] != 0 ]]; then + preexec_functions=(_p9k_preexec1 ${(@)preexec_functions:#_p9k_preexec1}) + fi + if [[ $preexec_functions[-1] != _p9k_preexec2 && $preexec_functions[(I)_p9k_preexec2] != 0 ]]; then + preexec_functions=(${(@)preexec_functions:#_p9k_preexec2} _p9k_preexec2) fi } @@ -6644,7 +6655,7 @@ prompt_powerlevel9k_setup() { setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} no_aliases prompt_powerlevel9k_teardown __p9k_enabled=1 - add-zsh-hook preexec _p9k_preexec + typeset -ga preexec_functions=(_p9k_preexec1 $preexec_functions _p9k_preexec2) typeset -ga precmd_functions=(_p9k_do_nothing $precmd_functions _p9k_precmd) } From 9586e24dfb71752afa04db77ad7e79c7430b883b Mon Sep 17 00:00:00 2001 From: romkatv Date: Mon, 20 Jan 2020 17:45:23 +0100 Subject: [PATCH 2/2] add color selection dialog for lean-8colors; remove space before prompt char in lean-* when it's the first segment on the line --- config/p10k-lean-8colors.zsh | 7 +++- config/p10k-lean.zsh | 3 ++ internal/wizard.zsh | 74 ++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/config/p10k-lean-8colors.zsh b/config/p10k-lean-8colors.zsh index cbcebccb..55ee28b4 100644 --- a/config/p10k-lean-8colors.zsh +++ b/config/p10k-lean-8colors.zsh @@ -181,7 +181,7 @@ # POWERLEVEL9K_MULTILINE_FIRST_PROMPT_GAP_CHAR=' ' below. typeset -g POWERLEVEL9K_SHOW_RULER=false typeset -g POWERLEVEL9K_RULER_CHAR='─' # reasonable alternative: '·' - typeset -g POWERLEVEL9K_RULER_FOREGROUND= + typeset -g POWERLEVEL9K_RULER_FOREGROUND=7 # Filler between left and right prompt on the first prompt line. You can set it to '·' or '─' # to make it easier to see the alignment between left and right prompt and to separate prompt @@ -192,7 +192,7 @@ typeset -g POWERLEVEL9K_MULTILINE_FIRST_PROMPT_GAP_CHAR=' ' if [[ $POWERLEVEL9K_MULTILINE_FIRST_PROMPT_GAP_CHAR != ' ' ]]; then # The color of the filler. - typeset -g POWERLEVEL9K_MULTILINE_FIRST_PROMPT_GAP_FOREGROUND= + typeset -g POWERLEVEL9K_MULTILINE_FIRST_PROMPT_GAP_FOREGROUND=7 # Add a space between the end of left prompt and the filler. typeset -g POWERLEVEL9K_LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL=' ' # Add a space between the filler and the start of right prompt. @@ -223,7 +223,10 @@ # Prompt symbol in overwrite vi mode. typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIOWR_CONTENT_EXPANSION='▶' typeset -g POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=true + # No line terminator if prompt_char is the last segment. typeset -g POWERLEVEL9K_PROMPT_CHAR_LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL='' + # No line introducer if prompt_char is the first segment. + typeset -g POWERLEVEL9K_PROMPT_CHAR_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL= ##################################[ dir: current directory ]################################## # Default current directory color. diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index f03877f3..22da5a05 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -223,7 +223,10 @@ # Prompt symbol in overwrite vi mode. typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIOWR_CONTENT_EXPANSION='▶' typeset -g POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=true + # No line terminator if prompt_char is the last segment. typeset -g POWERLEVEL9K_PROMPT_CHAR_LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL='' + # No line introducer if prompt_char is the first segment. + typeset -g POWERLEVEL9K_PROMPT_CHAR_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL= ##################################[ dir: current directory ]################################## # Default current directory color. diff --git a/internal/wizard.zsh b/internal/wizard.zsh index 00966da7..abfd0598 100755 --- a/internal/wizard.zsh +++ b/internal/wizard.zsh @@ -34,7 +34,6 @@ local -ri wizard_columns=$((COLUMNS < 80 ? COLUMNS : 80)) local -ri prompt_indent=2 local -ra bg_color=(240 238 236 234) -local -ra frame_color=(244 242 240 238) local -ra sep_color=(248 246 244 242) local -ra prefix_color=(250 248 246 244) @@ -55,7 +54,7 @@ local -r slanted_bar='\uE0BD' local -ra lean_left=( '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+$extra_icons[1] }%31F$extra_icons[2]%B%39F~%b%31F/%B%39Fsrc%b%f $prefixes[1]%76F$extra_icons[3]master%f ' - '%$frame_color[$color]F╰─ ' '%76F❯%f ${buffer:-█}' + '%$frame_color[$color]F╰─' '%76F❯%f ${buffer:-█}' ) local -ra lean_right=( @@ -64,13 +63,13 @@ local -ra lean_right=( ) local -ra lean_8colors_left=( - '╭─ ' '${extra_icons[1]:+$extra_icons[1] }%4F$extra_icons[2]%4F~/src%f $prefixes[1]%2F$extra_icons[3]master%f ' - '╰─ ' '%2F❯%f ${buffer:-█}' + '%$frame_color[$color]F╭─ ' '${extra_icons[1]:+$extra_icons[1] }%4F$extra_icons[2]%4F~/src%f $prefixes[1]%2F$extra_icons[3]master%f ' + '%$frame_color[$color]F╰─' '%2F❯%f ${buffer:-█}' ) local -ra lean_8colors_right=( - ' $prefixes[2]%3F$extra_icons[4]5s%f${show_time:+ $prefixes[3]%6F$extra_icons[5]16:23:42%f}' ' ─╮' - '' ' ─╯' + ' $prefixes[2]%3F$extra_icons[4]5s%f${show_time:+ $prefixes[3]%6F$extra_icons[5]16:23:42%f}' ' %$frame_color[$color]F─╮%f' + '' ' %$frame_color[$color]F─╯%f' ) local -ra classic_left=( @@ -151,8 +150,7 @@ function print_prompt() { (( num_lines == 2 && i == 1 )) && local fill=$gap_char || local fill=' ' print -n -- ${(pl:$prompt_indent:: :)} print -nP -- $l - [[ $style == lean_8colors ]] && local gap_color='%f' || local gap_color="%$frame_color[$color]F" - print -nP -- "$gap_color${(pl:$gap::$fill:)}%f" + print -nP -- "%$frame_color[$color]F${(pl:$gap::$fill:)}%f" print -P -- $r done } @@ -631,7 +629,12 @@ function ask_color_scheme() { q) quit;; r) return 1;; 1) style=lean; break;; - 2) style=lean_8colors; break;; + 2) + style=lean_8colors + frame_color=(0 7 2 4) + color_name=(Black White Green Blue) + break + ;; esac done } @@ -647,19 +650,19 @@ function ask_color() { clear flowing -c "%BPrompt Color%b" print -n $nl - print -P "%B(1) Lightest.%b" + print -P "%B(1) $color_name[1].%b" print -n $nl color=1 print_prompt print -P "" - print -P "%B(2) Light.%b" + print -P "%B(1) $color_name[2].%b" print -n $nl color=2 print_prompt print -P "" - print -P "%B(3) Dark.%b" + print -P "%B(1) $color_name[3].%b" print -n $nl color=3 print_prompt print -P "" - print -P "%B(4) Darkest.%b" + print -P "%B(1) $color_name[4].%b" print -n $nl color=4 print_prompt print -P "" @@ -672,16 +675,14 @@ function ask_color() { case $key in q) quit;; r) return 1;; - 1) color=1; options+=lightest; break;; - 2) color=2; options+=light; break;; - 3) color=3; options+=dark; break;; - 4) color=4; options+=darkest; break;; + [1-4]) color=$key; break;; esac done + options+=${(L)color_name[color]} } function ask_ornaments_color() { - [[ $style != (rainbow|lean) || $num_lines == 1 ]] && return + [[ $style != (rainbow|lean*) || $num_lines == 1 ]] && return [[ $gap_char == ' ' && $left_frame == 0 && $right_frame == 0 ]] && return if [[ $LINES -lt 26 ]]; then local nl='' @@ -695,19 +696,19 @@ function ask_ornaments_color() { clear flowing -c "%B${(j: & :)ornaments} Color%b" print -n $nl - print -P "%B(1) Lightest.%b" + print -P "%B(1) $color_name[1].%b" print -n $nl color=1 print_prompt print -P "" - print -P "%B(2) Light.%b" + print -P "%B(2) $color_name[2].%b" print -n $nl color=2 print_prompt print -P "" - print -P "%B(3) Dark.%b" + print -P "%B(3) $color_name[3].%b" print -n $nl color=3 print_prompt print -P "" - print -P "%B(4) Darkest.%b" + print -P "%B(4) $color_name[4].%b" print -n $nl color=4 print_prompt print -P "" @@ -720,12 +721,10 @@ function ask_ornaments_color() { case $key in q) quit;; r) return 1;; - 1) color=1; options+=lightest; break;; - 2) color=2; options+=light; break;; - 3) color=3; options+=dark; break;; - 4) color=4; options+=darkest; break;; + [1-4]) color=$key; break;; esac done + options+=${(L)color_name[color]}-ornaments } function ask_time() { @@ -1545,6 +1544,7 @@ function generate_config() { sub LEFT_SUBSEGMENT_SEPARATOR "'$left_subsep'" sub RIGHT_SUBSEGMENT_SEPARATOR "'$right_subsep'" fi + sub RULER_FOREGROUND $frame_color[$color] sub MULTILINE_FIRST_PROMPT_GAP_FOREGROUND $frame_color[$color] sub MULTILINE_FIRST_PROMPT_PREFIX "'%$frame_color[$color]F╭─'" sub MULTILINE_NEWLINE_PROMPT_PREFIX "'%$frame_color[$color]F├─'" @@ -1621,22 +1621,18 @@ function generate_config() { fi if [[ $style == lean* ]]; then - if [[ $style == lean ]]; then - local c="%$frame_color[$color]F" - sub MULTILINE_FIRST_PROMPT_GAP_FOREGROUND $frame_color[$color] - else - local c= - fi + sub RULER_FOREGROUND $frame_color[$color] + sub MULTILINE_FIRST_PROMPT_GAP_FOREGROUND $frame_color[$color] if (( right_frame )); then - sub MULTILINE_FIRST_PROMPT_SUFFIX "'$c─╮'" - sub MULTILINE_NEWLINE_PROMPT_SUFFIX "'$c─┤'" - sub MULTILINE_LAST_PROMPT_SUFFIX "'$c─╯'" + sub MULTILINE_FIRST_PROMPT_SUFFIX "'%$frame_color[$color]F─╮'" + sub MULTILINE_NEWLINE_PROMPT_SUFFIX "'%$frame_color[$color]F─┤'" + sub MULTILINE_LAST_PROMPT_SUFFIX "'%$frame_color[$color]F─╯'" sub RIGHT_PROMPT_LAST_SEGMENT_END_SYMBOL "' '" fi if (( left_frame )); then - sub MULTILINE_FIRST_PROMPT_PREFIX "'$c╭─'" - sub MULTILINE_NEWLINE_PROMPT_PREFIX "'$c├─'" - sub MULTILINE_LAST_PROMPT_PREFIX "'$c╰─'" + sub MULTILINE_FIRST_PROMPT_PREFIX "'%$frame_color[$color]F╭─'" + sub MULTILINE_NEWLINE_PROMPT_PREFIX "'%$frame_color[$color]F├─'" + sub MULTILINE_LAST_PROMPT_PREFIX "'%$frame_color[$color]F╰─'" sub LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL "' '" fi fi @@ -1740,6 +1736,8 @@ while true; do local -i num_lines=0 empty_line=0 color=2 left_frame=1 right_frame=1 transient_prompt=0 local -i cap_diamond=0 cap_python=0 cap_debian=0 cap_narrow_icons=0 cap_lock=0 local -a extra_icons=('' '' '') + local -a frame_color=(244 242 240 238) + local -a color_name=(Lightest Light Dark Darkest) local -a prefixes=('' '') local -a options=()