From 5baecd66db3ce32ef76fc23fc6f43f97f8d3de29 Mon Sep 17 00:00:00 2001 From: romkatv Date: Sun, 26 Apr 2020 19:32:46 +0200 Subject: [PATCH] wizard now reacts to terminal size changes and can function at much smaller terminal dimensions; fixes #649 --- internal/configure.zsh | 4 +- internal/wizard.zsh | 2094 ++++++++++++++++++---------------------- 2 files changed, 922 insertions(+), 1176 deletions(-) diff --git a/internal/configure.zsh b/internal/configure.zsh index b8bc576..5b3df9a 100644 --- a/internal/configure.zsh +++ b/internal/configure.zsh @@ -1,5 +1,5 @@ -typeset -gr __p9k_wizard_columns=55 -typeset -gr __p9k_wizard_lines=21 +typeset -gr __p9k_wizard_columns=51 +typeset -gr __p9k_wizard_lines=12 typeset -gr __p9k_zd=${ZDOTDIR:-$HOME} typeset -gr __p9k_zd_u=${${${(q)__p9k_zd}/#(#b)${(q)HOME}(|\/*)/'~'$match[1]}//\%/%%} typeset -gr __p9k_zshrc=${${:-$__p9k_zd/.zshrc}:A} diff --git a/internal/wizard.zsh b/internal/wizard.zsh index dcae09e..1cbebda 100755 --- a/internal/wizard.zsh +++ b/internal/wizard.zsh @@ -14,7 +14,16 @@ if (( OPTIND <= ARGC )); then return 1 fi -(( $+terminfo[smcup] && $+terminfo[rmcup] )) && echoti smcup +if (( $+terminfo[smcup] && $+terminfo[rmcup] )) && echoti smcup 2>/dev/null; then + function restore_screen() { + echoti rmcup 2>/dev/null + function restore_screen() {} + } +else + function restore_screen() {} +fi + +{ # always local -ri force @@ -113,6 +122,10 @@ function prompt_length() { } function print_prompt() { + [[ $parameters[extra_icons] == scalar* ]] && eval "local -a extra_icons=$extra_icons" + [[ $parameters[pure_color] == scalar* ]] && eval "local -A pure_color=$pure_color" + [[ $parameters[prefixes] == scalar* ]] && eval "local -a prefixes=$prefixes" + local left=${style}_left local right=${style}_right left=("${(@P)left}") @@ -140,7 +153,8 @@ function print_prompt() { elif (( left_indent )); then (( --left_indent )) else - break # not supposed to happen; will result in overflow if it does + print -P ' [%3Fnot enough horizontal space to display this%f]' + return 0 fi done local -i i @@ -167,6 +181,7 @@ function href() { } function flowing() { + (( ${wizard_columns:-0} )) || local -i wizard_columns=COLUMNS local opt local -i centered indentation while getopts 'ci:' opt; do @@ -201,40 +216,57 @@ function flowing() { } function clear() { - if (( $+commands[clear] )); then - command clear - elif zmodload zsh/termcap 2>/dev/null; then - echotc cl - else - print -n -- "\e[H\e[J" + if (( $+commands[clear] )) && command clear 2>/dev/null; then + return fi + echoti clear 2>/dev/null + print -n -- "\e[H\e[2J\e[3J" +} + +function hide_cursor() { + (( $+terminfo[cnorm] )) || return + echoti civis 2>/dev/null +} + +function show_cursor() { + echoti cnorm 2>/dev/null +} + +function consume_input() { + local key + while read -t0 key; do true; done } function quit() { + consume_input if [[ $1 == '-c' ]]; then - print -P "" - else - if (( $+terminfo[smcup] && $+terminfo[rmcup] )); then - echoti rmcup - print - else - clear - fi + print -Pr -- '' + print -Pr -- '%b%k%f%u%s' + print -Pr -- '%F{3}--- stack trace (most recent call first) ---%f' + print -lr -- $funcfiletrace + print -Pr -- '%F{3}--- end of stack trace ---%f' + print -Pr -- '' + print -Pr -- 'Press %BENTER%b to continue.' + hide_cursor + read -s fi + restore_screen + print if (( force )); then - print -P "Powerlevel10k configuration wizard has been aborted. To run it again, type:" + flowing Powerlevel10k configuration wizard has been aborted. To run it again, type: print -P "" print -P " %2Fp10k%f %Bconfigure%b" print -P "" else - print -P "Powerlevel10k configuration wizard has been aborted. It will run again" - print -P "next time unless you define at least one Powerlevel10k configuration option." - print -P "To define an option that does nothing except for disabling Powerlevel10k" - print -P "configuration wizard, type the following command:" + flowing \ + Powerlevel10k configuration wizard has been aborted. It will run again \ + next time unless you define at least one Powerlevel10k configuration option. \ + To define an option that does nothing except for disabling Powerlevel10k \ + configuration wizard, type the following command: print -P "" print -P " %2Fecho%f %3F'POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true'%f >>! $__p9k_zshrc_u" print -P "" - print -P "To run Powerlevel10k configuration wizard right now, type:" + flowing To run Powerlevel10k configuration wizard right now, type: print -P "" print -P " %2Fp10k%f %Bconfigure%b" print -P "" @@ -242,6 +274,136 @@ function quit() { exit 1 } +local screen_widgets=() +local -i prompt_idx +local choice + +function add_widget() { + local priority=$1 + shift + local render="${(j: :)${(@q)*}}" + screen_widgets+=("$priority" "$render") +} + +function render_screen_pass() { + local -i pass=$1 + local -i prev_pass cur_pass + local prev_render cur_render + for cur_pass cur_render in "${(@)screen_widgets}" 0 ''; do + if (( prev_pass <= pass && (cur_pass == 0 || cur_pass > pass) )); then + eval $prev_render + fi + prev_pass=cur_pass + prev_render=$cur_render + done +} + +function render_screen() { + { + hide_cursor + stty -echo 2>/dev/null + while true; do + while true; do + local -i wizard_columns=$((COLUMNS > 88 ? 88 : COLUMNS)) + local -i wizard_lines=LINES + if (( wizard_columns < __p9k_wizard_columns )); then + clear + flowing -c %1FNot enough horizontal space.%f + print + flowing Make terminal window %Bwider%b or press %BCtrl-C%b to abort Powerlevel10k configuration wizard. + elif (( wizard_lines < __p9k_wizard_lines )); then + clear + flowing -c %1FNot enough vertical space.%f + print + flowing Make terminal window %Btaller%b or press %BCtrl-C%b to abort Powerlevel10k configuration wizard. + else + break + fi + while (( (COLUMNS > 88 ? 88 : COLUMNS) == wizard_columns && LINES == wizard_lines )); do + sleep 1 + done + done + + local -a passes + () { + local -i pass + local render + for pass render in "${(@)screen_widgets}"; do + passes+=$pass + done + passes=(${(onu)passes}) + } + + local -i pass + for pass in $passes; do + local content="$(render_screen_pass $pass)" + local lines=("${(@f)content}") + (( $#lines > wizard_lines )) && continue + clear + print -rn -- $content + return 0 + done + + clear + flowing -c %1FNot enough vertical space.%f + print + flowing Make terminal window %Btaller%b or press %BCtrl-C%b to abort Powerlevel10k configuration wizard. + while (( (COLUMNS > 88 ? 88 : COLUMNS) == wizard_columns && LINES == wizard_lines )); do + sleep 1 + done + done + } always { + stty echo 2>/dev/null + show_cursor + } +} + +function add_prompt_n() { + add_widget 0 "$@" print_prompt + local var + for var; do + eval "local $var" + done + if (( num_lines == 2 )); then + add_widget $(( 100 - ++prompt_idx )) print -P ' [%3Fnot enough vertical space to display this%f]' + fi +} + +function add_prompt() { + add_widget 0 print + add_widget 1 + add_prompt_n "$@" + add_widget 0 print + add_widget 2 +} + +function ask() { + local choices=$1 + local -i lines columns + add_widget 0 print -P "(q) Quit and do nothing." + add_widget 0 print + add_widget 0 print -P "%BChoice [${choices}q]: %b" + while true; do + =true + if (( LINES != lines || COLUMNS != columns )); then + render_screen + lines=wizard_lines + columns=wizard_columns + fi + typeset -g choice= + if read -t1 -k choice; then + if [[ $choice == q ]]; then + quit + fi + if [[ $choices == *$choice* ]]; then + screen_widgets=() + prompt_idx=0 + return + fi + fi + done +} + local -i greeting_printed=0 function print_greeting() { @@ -375,7 +537,9 @@ function install_font() { run_command "" /usr/bin/defaults read com.googlecode.iterm2 sleep 3 print -P " %2FOK%f" - clear + sleep 1 + restore_screen + print flowing +c "%2FMeslo Nerd Font%f" successfully installed. print -P "" flowing +c Please "%Brestart iTerm2%b" for the changes to take effect. @@ -404,37 +568,37 @@ function install_font() { function ask_font() { (( can_install_font )) || return 0 - { - while true; do - clear - (( greeting_printed )) || print_greeting - if (( iterm2_old_font )); then - flowing -c A new version of '%2FMeslo Nerd Font%f' is available. "%BInstall?" - else - flowing -c "%BInstall %b%2FMeslo Nerd Font%f%B?%b" - fi - print -P "" - print -P "" - print -P "%B(y) Yes (recommended).%b" - print -P "" - print -P "%B(n) No. Use the current font.%b" - print -P "" - print -P "(q) Quit and do nothing." - print -P "" + add_widget 0 print_greeting + if (( iterm2_old_font )); then + add_widget 0 flowing -c A new version of '%2FMeslo Nerd Font%f' is available. '%BInstall?%b' + else + add_widget 0 flowing -c %BInstall '%b%2FMeslo Nerd Font%f%B?%b' + fi + add_widget 0 print + add_widget 0 print -P "%B(y) Yes (recommended).%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(n) No. Use the current font.%b" + add_widget 0 print + add_widget 1 + ask yn + greeting_printed=1 + case $choice in + y) + ask_remove_font || return + install_font + ;; + n) ;; + esac + return 0 +} - local key= - read -k key${(%):-"?%BChoice [ynq]: %b"} || quit -c - case $key in - q) quit;; - y) ask_remove_font || return; install_font; break;; - n) break;; - esac - done - - return 0 - } always { - greeting_printed=1 - } +function print_file_path() { + local file=$1 + if (( ${(m)#file} > wizard_columns - 2 )); then + file[wizard_columns-4,-1]='...' + fi + add_widget 0 print -P " %B${file//\%/%%}%b" } function ask_remove_font() { @@ -449,204 +613,158 @@ function ask_remove_font() { [[ -w ${font:h} ]] || protected=1 done (( $#fonts )) || return 0 - while true; do - clear - flowing -c "A variant of %2FMeslo Nerd Font%f" is already installed. - print -P "" - for font in $fonts; do - print -P " %B${font//\%/%%}%b" - done - print -P "" - if (( protected )); then - if (( $#fonts == 1 )); then - flowing Please %Bdelete%b this file and run '%2Fp10k%f %Bconfigure%b.' - else - flowing Please %Bdelete%b these files and run '%2Fp10k%f %Bconfigure%b.' - fi - print - exit 1 - fi - if (( $#fonts == 1 )); then - flowing -c "%BDelete this file?%b" - else - flowing -c "%BDelete these files?%b" - fi - print -P "" - print -P "%B(y) Yes (recommended).%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [yrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) zf_rm -f -- $fonts || quit -c; break;; - esac + add_widget 0 flowing -c A variant of "%2FMeslo Nerd Font%f" is already installed. + add_widget 0 print -P "" + for font in $fonts; do + add_widget 0 print_file_path $font done - + add_widget 0 print -P "" + if (( protected )); then + if (( $#fonts == 1 )); then + add_widget 0 flowing Please %Bdelete%b this file and run '%2Fp10k%f %Bconfigure%b.' + else + add_widget 0 flowing Please %Bdelete%b these files and run '%2Fp10k%f %Bconfigure%b.' + fi + add_widget 0 print + restore_screen + local pass render + for pass render in "${(@)screen_widgets}"; do + (( pass == 0 )) && eval $render + done + exit 1 + fi + if (( $#fonts == 1 )); then + add_widget 0 flowing -c "%BDelete this file?%b" + else + add_widget 0 flowing -c "%BDelete these files?%b" + fi + add_widget 0 print -P "" + add_widget 0 print -P "%B(y) Yes (recommended).%b" + add_widget 0 print -P "" + add_widget 0 print -P "(r) Restart from the beginning." + ask yr + case $choice in + r) return 1;; + y) zf_rm -f -- $fonts || quit -c;; + esac return 0 } function ask_diamond() { - while true; do - local extra= - clear - print_greeting - flowing -c "%BDoes this look like a %b%2Fdiamond%f%B (rotated square)?%b" - flowing -c "reference: $(href https://graphemica.com/%E2%97%86)" - print -P "" - flowing -c -- "---> \uE0B2\uE0B0 <---" - print -P "" - print -P "%B(y) Yes.%b" - print -P "" - print -P "%B(n) No.%b" - print -P "" - if (( can_install_font )); then - extra+=r - print -P "(r) Restart from the beginning." - fi - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [yn${extra}q]: %b"} || quit -c - case $key in - q) quit;; - r) [[ $extra == *r* ]] && { greeting_printed=1; return 1 };; - y) cap_diamond=1; break;; - n) cap_diamond=0; break;; - esac - done + local extra + add_widget 0 print_greeting + add_widget 0 flowing -c %BDoes this look like a%b %2Fdiamond%f '%B(rotated square)?%b' + add_widget 0 flowing -c reference: "$(href https://graphemica.com/%E2%97%86)" + add_widget 0 print + add_widget 0 flowing -c -- "---> \uE0B2\uE0B0 <---" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(y) Yes.%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(n) No.%b" + add_widget 0 print + add_widget 1 + if (( can_install_font )); then + extra+=r + add_widget 0 print -P "(r) Restart from the beginning." + fi + ask yn$extra greeting_printed=1 + case $choice in + r) return 1;; + y) cap_diamond=1;; + n) cap_diamond=0;; + esac return 0 } function ask_lock() { - while true; do - clear - [[ -n $2 ]] && flowing -c "$2" - flowing -c "%BDoes this look like a %b%2Flock%f%B?%b" - flowing -c "reference: $(href https://fontawesome.com/icons/lock)" - print -P "" - flowing -c -- "---> $1 <---" - print -P "" - print -P "%B(y) Yes.%b" - print -P "" - print -P "%B(n) No.%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [ynrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) cap_lock=1; break;; - n) cap_lock=0; break;; - esac - done - + [[ -n $2 ]] && add_widget 0 flowing -c "$2" + add_widget 0 flowing -c "%BDoes this look like a %b%2Flock%f%B?%b" + add_widget 0 flowing -c "reference: $(href https://fontawesome.com/icons/lock)" + add_widget 0 print + add_widget 0 flowing -c -- "---> $1 <---" + add_widget 0 print + add_widget 0 print -P "%B(y) Yes.%b" + add_widget 0 print + add_widget 0 print -P "%B(n) No.%b" + add_widget 0 print + add_widget 0 print -P "(r) Restart from the beginning." + ask ynr + case $choice in + r) return 1;; + y) cap_lock=1;; + n) cap_lock=0;; + esac return 0 } function ask_python() { - while true; do - clear - flowing -c "%BDoes this look like a %b%2FPython logo%f%B?%b" - flowing -c "reference: $(href https://fontawesome.com/icons/python)" - print -P "" - flowing -c -- "---> \uE63C <---" - print -P "" - print -P "%B(y) Yes.%b" - print -P "" - print -P "%B(n) No.%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [ynrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) cap_python=1; break;; - n) cap_python=0; break;; - esac - done - + add_widget 0 add_widget 0 flowing -c %BDoes this look like a "%b%2FPython logo%f%B?%b" + add_widget 0 add_widget 0 flowing -c reference: "$(href https://fontawesome.com/icons/python)" + add_widget 0 add_widget 0 print -P "" + add_widget 0 add_widget 0 flowing -c -- "---> \uE63C <---" + add_widget 0 add_widget 0 print -P "" + add_widget 0 add_widget 0 print -P "%B(y) Yes.%b" + add_widget 0 add_widget 0 print -P "" + add_widget 0 add_widget 0 print -P "%B(n) No.%b" + add_widget 0 add_widget 0 print -P "" + add_widget 0 add_widget 0 print -P "(r) Restart from the beginning." + ask ynr + case $choice in + r) return 1;; + y) cap_python=1;; + n) cap_python=0;; + esac return 0 } function ask_arrow() { - while true; do - clear - flowing -c "%BDoes this look like %b%2F><%f%B but taller and fatter?%b" - print -P "" - flowing -c -- "---> \u276F\u276E <---" - print -P "" - print -P "%B(y) Yes.%b" - print -P "" - print -P "%B(n) No.%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [ynrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) cap_arrow=1; break;; - n) cap_arrow=0; break;; - esac - done - + add_widget 0 flowing -c %BDoes this look like%b "%2F><%f" %Bbut taller and "fatter?%b" + add_widget 0 print -P "" + add_widget 0 flowing -c -- "---> \u276F\u276E <---" + add_widget 0 print -P "" + add_widget 0 print -P "%B(y) Yes.%b" + add_widget 0 print -P "" + add_widget 0 print -P "%B(n) No.%b" + add_widget 0 print -P "" + add_widget 0 print -P "(r) Restart from the beginning." + ask ynr + case $choice in + r) return 1;; + y) cap_arrow=1;; + n) cap_arrow=0;; + esac return 0 } function ask_debian() { - while true; do - clear - flowing -c "%BDoes this look like a %b%2FDebian logo%f%B (swirl/spiral)?%b" - flowing -c "reference: $(href https://debian.org/logos/openlogo-nd.svg)" - print -P "" - flowing -c -- "---> \uF306 <---" - print -P "" - print -P "%B(y) Yes.%b" - print -P "" - print -P "%B(n) No.%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [ynrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) cap_debian=1; break;; - n) cap_debian=0; break;; - esac - done - + add_widget 0 flowing -c %BDoes this look like a%b "%2FDebian logo%f" "%B(swirl/spiral)?%b" + add_widget 0 flowing -c reference: "$(href https://debian.org/logos/openlogo-nd.svg)" + add_widget 0 print -P "" + add_widget 0 flowing -c -- "---> \uF306 <---" + add_widget 0 print -P "" + add_widget 0 print -P "%B(y) Yes.%b" + add_widget 0 print -P "" + add_widget 0 print -P "%B(n) No.%b" + add_widget 0 print -P "" + add_widget 0 print -P "(r) Restart from the beginning." + ask ynr + case $choice in + r) return 1;; + y) cap_debian=1;; + n) cap_debian=0;; + esac return 0 } function ask_icon_padding() { - local -i saves=5 if [[ $POWERLEVEL9K_MODE == (powerline|compatible|ascii) ]]; then POWERLEVEL9K_ICON_PADDING=none - (( saved_columns += saves )) return 0 fi + local text="X" text+="%1F${icons[VCS_GIT_ICON]// }%fX" text+="%2F${icons[VCS_GIT_GITHUB_ICON]// }%fX" @@ -656,42 +774,31 @@ function ask_icon_padding() { text+="%6F${icons[HOME_SUB_ICON]// }%fX" text+="%1F${icons[FOLDER_ICON]// }%fX" text+="%2F${icons[RAM_ICON]// }%fX" - while true; do - clear - flowing -c "%BDo all these icons %b%2Ffit between the crosses%f%B?%b" - print -P "" - flowing -c -- "---> $text <---" - print -P "" - flowing +c -i 5 "%B(y) Yes." Icons are very close to the crosses but there is "%b%2Fno overlap%f%B.%b" - print -P "" - print -P "%B(n) No. Some icons %b%2Foverlap%f%B neighbouring crosses.%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [ynrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) - POWERLEVEL9K_ICON_PADDING=none - options+='small icons' - (( saved_columns += saves )) - break - ;; - n) - POWERLEVEL9K_ICON_PADDING=moderate - options+='large icons' - up_triangle+=' ' - down_triangle+=' ' - slanted_bar='\uE0BD ' - break - ;; - esac - done + add_widget 0 flowing -c %BDo all these icons "%b%2Ffit between the crosses%f%B?%b" + add_widget 0 print -P "" + add_widget 0 flowing -c -- "---> $text <---" + add_widget 0 print -P "" + add_widget 0 flowing +c -i 5 "%B(y) Yes." Icons are very close to the crosses but there is "%b%2Fno overlap%f%B.%b" + add_widget 0 print -P "" + add_widget 0 flowing +c -i 5 "%B(n) No." Some icons "%b%2Foverlap%f%B" neighbouring crosses.%b + add_widget 0 print -P "" + add_widget 0 print -P "(r) Restart from the beginning." + ask ynr + case $choice in + r) return 1;; + y) + POWERLEVEL9K_ICON_PADDING=none + options+='small icons' + ;; + n) + POWERLEVEL9K_ICON_PADDING=moderate + options+='large icons' + up_triangle+=' ' + down_triangle+=' ' + slanted_bar='\uE0BD ' + ;; + esac return 0 } @@ -703,231 +810,147 @@ function ask_style() { frame_color=(0 7 2 4) color_name=(Black White Green Blue) options+=lean_8colors - (( saved_columns += 5 )) return 0 fi - - if (( cap_diamond && LINES < 26 )); then - local nl='' - else - local nl=$'\n' + local extra + add_widget 0 flowing -c "%BPrompt Style%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) Lean.%b" + add_prompt style=lean left_frame=0 right_frame=0 + add_widget 0 print -P "%B(2) Classic.%b" + add_prompt style=classic + add_widget 0 print -P "%B(3) Rainbow.%b" + add_prompt style=rainbow + if [[ $POWERLEVEL9K_MODE != ascii ]]; then + extra+=4 + add_widget 0 print -P "%B(4) Pure.%b" + add_prompt style=pure fi - - while true; do - local extra= - clear - flowing -c "%BPrompt Style%b" - print -n $nl - print -P "%B(1) Lean.%b" - print -n $nl - style=lean left_frame=0 right_frame=0 print_prompt - print -P "" - print -P "%B(2) Classic.%b" - print -n $nl - style=classic print_prompt - print -P "" - print -P "%B(3) Rainbow.%b" - print -n $nl - style=rainbow print_prompt - print -P "" - if [[ $POWERLEVEL9K_MODE != ascii ]]; then - extra+=4 - print -P "%B(4) Pure.%b" - print -n $nl - style=pure print_prompt - print -P "" - fi - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [123${extra}rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) style=lean; left_frame=0; right_frame=0; options+=lean; (( saved_columns += 5 )); break;; - 2) style=classic; options+=classic; break;; - 3) style=rainbow; options+=rainbow; break;; - 4) - if [[ $extra == *4* ]]; then - style=pure - empty_line=1 - options+=pure - (( saved_columns += 5 )) - break - fi - ;; - esac - done - + add_widget 0 print -P "(r) Restart from the beginning." + ask 123${extra}r + case $choice in + r) return 1;; + 1) style=lean; left_frame=0; right_frame=0; options+=lean;; + 2) style=classic; options+=classic;; + 3) style=rainbow; options+=rainbow;; + 4) style=pure; empty_line=1; options+=pure;; + esac return 0 } function ask_charset() { [[ $style == (lean*|classic|rainbow) && $POWERLEVEL9K_MODE != ascii ]] || return 0 - - while true; do - clear - flowing -c "%BCharacter Set%b" - print -P "" - print -P "%B(1) Unicode.%b" - print -P "" - print_prompt - print -P "" - print -P "%B(2) ASCII.%b" - print -P "" - left_sep= right_sep= left_subsep='|' right_subsep='|' left_head= \ - right_head= prompt_char='>' left_frame=0 right_frame=0 print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) options+=unicode; break;; - 2) - left_sep= - right_sep= - left_subsep='|' - right_subsep='|' - left_head= - right_head= - prompt_char='>' - left_frame=0 - right_frame=0 - POWERLEVEL9K_MODE=ascii - POWERLEVEL9K_ICON_PADDING=none - cap_diamond=0 - cap_python=0 - cap_debian=0 - cap_lock=0 - cap_arrow=0 - break - ;; - esac - done - + add_widget 0 flowing -c "%BCharacter Set%b" + add_widget 0 print -P "" + add_widget 1 + add_widget 0 print -P "%B(1) Unicode.%b" + add_prompt + add_widget 0 print -P "%B(2) ASCII.%b" + add_prompt \ + left_sep= \ + right_sep= \ + left_subsep='|' \ + right_subsep='|' \ + left_head= \ + right_head= \ + prompt_char='>' \ + left_frame=0 \ + right_frame=0 + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) options+=unicode;; + 2) + options+=ascii + left_sep= + right_sep= + left_subsep='|' + right_subsep='|' + left_head= + right_head= + prompt_char='>' + left_frame=0 + right_frame=0 + POWERLEVEL9K_MODE=ascii + POWERLEVEL9K_ICON_PADDING=none + cap_diamond=0 + cap_python=0 + cap_debian=0 + cap_lock=0 + cap_arrow=0 + ;; + esac return 0 } function ask_color_scheme() { (( terminfo[colors] < 256 )) && return - if [[ $style == lean ]]; then - while true; do - clear - flowing -c "%BPrompt Colors%b" - print -P "" - print -P "%B(1) 256 colors.%b" - print -P "" - style=lean print_prompt - print -P "" - print -P "%B(2) 8 colors.%b" - print -P "" - style=lean_8colors print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) style=lean; break;; - 2) - style=lean_8colors - frame_color=(0 7 2 4) - color_name=(Black White Green Blue) - break - ;; - esac - done + add_widget 0 flowing -c "%BPrompt Colors%b" + add_widget 0 print -P "" + add_widget 1 + add_widget 0 print -P "%B(1) 256 colors.%b" + add_prompt style=lean + add_widget 0 print -P "%B(2) 8 colors.%b" + add_prompt style=lean_8colors + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) style=lean;; + 2) + style=lean_8colors + frame_color=(0 7 2 4) + color_name=(Black White Green Blue) + ;; + esac options=(${options:#lean} $style) elif [[ $style == pure && $has_truecolor == 1 ]]; then - while true; do - clear - flowing -c "%BPrompt Colors%b" - print -P "" - print -P "%B(1) Original.%b" - print -P "" - pure_color=(${(kv)pure_original}) print_prompt - print -P "" - print -P "%B(2) Snazzy.%b" - print -P "" - pure_color=(${(kv)pure_snazzy}) print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) - pure_color=(${(kv)pure_original}) - options+=original - break - ;; - 2) - pure_color=(${(kv)pure_snazzy}) - options+=snazzy - break - ;; - esac - done + add_widget 0 flowing -c "%BPrompt Colors%b" + add_widget 0 print -P "" + add_widget 1 + add_widget 0 print -P "%B(1) Original.%b" + add_prompt "pure_color=(${(j: :)${(@q)${(@kv)pure_original}}})" + add_widget 0 print -P "%B(2) Snazzy.%b" + add_prompt "pure_color=(${(j: :)${(@q)${(@kv)pure_snazzy}}})" + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) + pure_color=(${(kv)pure_original}) + options+=original + ;; + 2) + pure_color=(${(kv)pure_snazzy}) + options+=snazzy + ;; + esac fi - return 0 } function ask_color() { [[ $style != classic ]] && return - if [[ $LINES -lt 26 ]]; then - local nl='' - else - local nl=$'\n' - fi - while true; do - clear - flowing -c "%BPrompt Color%b" - print -n $nl - print -P "%B(1) $color_name[1].%b" - print -n $nl - color=1 print_prompt - print -P "" - print -P "%B(2) $color_name[2].%b" - print -n $nl - color=2 print_prompt - print -P "" - print -P "%B(3) $color_name[3].%b" - print -n $nl - color=3 print_prompt - print -P "" - print -P "%B(4) $color_name[4].%b" - print -n $nl - color=4 print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [1234rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - [1-4]) color=$key; break;; - esac - done + add_widget 0 flowing -c "%BPrompt Color%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) $color_name[1].%b" + add_prompt color=1 + add_widget 0 print -P "%B(2) $color_name[2].%b" + add_prompt color=2 + add_widget 0 print -P "%B(3) $color_name[3].%b" + add_prompt color=3 + add_widget 0 print -P "%B(4) $color_name[4].%b" + add_prompt color=4 + add_widget 0 print -P "(r) Restart from the beginning." + ask 1234r + case $choice in + r) return 1;; + [1-4]) color=$choice;; + esac options+=${(L)color_name[color]} return 0 } @@ -935,114 +958,68 @@ function ask_color() { function ask_ornaments_color() { [[ $style != (rainbow|lean*) || $num_lines == 1 ]] && return [[ $gap_char == ' ' && $left_frame == 0 && $right_frame == 0 ]] && return - if [[ $LINES -lt 26 ]]; then - local nl='' - else - local nl=$'\n' - fi local ornaments=() [[ $gap_char != ' ' ]] && ornaments+=Connection (( left_frame || right_frame )) && ornaments+=Frame - while true; do - clear - flowing -c "%B${(j: & :)ornaments} Color%b" - print -n $nl - print -P "%B(1) $color_name[1].%b" - print -n $nl - color=1 print_prompt - print -P "" - print -P "%B(2) $color_name[2].%b" - print -n $nl - color=2 print_prompt - print -P "" - print -P "%B(3) $color_name[3].%b" - print -n $nl - color=3 print_prompt - print -P "" - print -P "%B(4) $color_name[4].%b" - print -n $nl - color=4 print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [1234rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - [1-4]) color=$key; break;; - esac - done + add_widget 0 flowing -c "%B${(j: & :)ornaments} Color%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) $color_name[1].%b" + add_prompt color=1 + add_widget 0 print -P "%B(2) $color_name[2].%b" + add_prompt color=2 + add_widget 0 print -P "%B(3) $color_name[3].%b" + add_prompt color=3 + add_widget 0 print -P "%B(4) $color_name[4].%b" + add_prompt color=4 + add_widget 0 print -P "(r) Restart from the beginning." + ask 1234r + case $choice in + r) return 1;; + [1-4]) color=$choice;; + esac options+=${(L)color_name[color]}-ornaments return 0 } function ask_time() { - while true; do - local extra= - clear - flowing -c "%BShow current time?%b" - print -P "" - print -P "%B(1) No.%b" - print -P "" - time= print_prompt - print -P "" - print -P "%B(2) 24-hour format.%b" - print -P "" - time=$time_24h print_prompt - print -P "" - print -P "%B(3) 12-hour format.%b" - print -P "" - time=$time_12h print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [123rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) time=; (( saved_columns += 12 )); break;; - 2) time=$time_24h; options+='24h time'; (( saved_columns += 3 )); break;; - 3) time=$time_12h; options+='12h time'; break;; - esac - done - + local extra + add_widget 0 flowing -c "%BShow current time?%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) No.%b" + add_prompt time= + add_widget 0 print -P "%B(2) 24-hour format.%b" + add_prompt time=$time_24h + add_widget 0 print -P "%B(3) 12-hour format.%b" + add_prompt time=$time_12h + add_widget 0 print -P "(r) Restart from the beginning." + ask 123r + case $choice in + r) return 1;; + 1) time=;; + 2) time=$time_24h; options+='24h time';; + 3) time=$time_12h; options+='12h time';; + esac return 0 } function ask_use_rprompt() { [[ $style != pure ]] && return - while true; do - clear - flowing -c "%BNon-permanent content location%b" - print -P "" - print -P "%B(1) Left.%b" - print -P "" - print_prompt - print -P "" - print -P "%B(2) Right.%b" - print -P "" - pure_use_rprompt= print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) break;; - 2) pure_use_rprompt=; options+=rpromt; break;; - esac - done - + add_widget 0 flowing -c "%BNon-permanent content location%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) Left.%b" + add_prompt + add_widget 0 print -P "%B(2) Right.%b" + add_prompt pure_use_rprompt= + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) ;; + 2) pure_use_rprompt=; options+=rpromt;; + esac return 0 } @@ -1092,15 +1069,7 @@ function os_icon_name() { } function ask_extra_icons() { - local -i saves=12 if [[ $style == pure || $POWERLEVEL9K_MODE == (powerline|compatible|ascii) ]]; then - (( saved_columns += saves )) - return 0 - fi - if (( wizard_columns + saved_columns < 69 )); then - prefixes=("$concise[@]") - options+=concise - (( saved_columns += saves )) return 0 fi local os_icon=${(g::)icons[$(os_icon_name)]} @@ -1112,388 +1081,240 @@ function ask_extra_icons() { branch_icon=${branch_icon// } local few=('' '' '' '' '') local many=("$os_icon" "$dir_icon " "$vcs_icon $branch_icon " "$duration_icon " "$time_icon ") - while true; do - clear - flowing -c "%BIcons%b" - print -P "" - print -P "%B(1) Few icons.%b" - print -P "" - extra_icons=("$few[@]") print_prompt - print -P "" - print -P "%B(2) Many icons.%b" - print -P "" - extra_icons=("$many[@]") print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) extra_icons=("$few[@]"); options+='few icons'; (( saved_columns += saves )); break;; - 2) extra_icons=("$many[@]"); options+='many icons'; break;; - esac - done - + add_widget 0 flowing -c "%BIcons%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) Few icons.%b" + add_prompt "extra_icons=(${(j: :)${(@q)few}})" + add_widget 0 print -P "%B(2) Many icons.%b" + add_prompt "extra_icons=(${(j: :)${(@q)many}})" + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) extra_icons=("$few[@]"); options+='few icons';; + 2) extra_icons=("$many[@]"); options+='many icons';; + esac return 0 } function ask_prefixes() { - local -i saves=11 if [[ $style == pure ]]; then - (( saved_columns += saves )) - return 0 - fi - if (( wizard_columns + saved_columns < 84 )); then - prefixes=("$concise[@]") - options+=concise - (( saved_columns += saves )) return 0 fi local concise=('' '' '') local fluent=('on ' 'took ' 'at ') - while true; do - clear - flowing -c "%BPrompt Flow%b" - print -P "" - print -P "%B(1) Concise.%b" - print -P "" - prefixes=("$concise[@]") print_prompt - print -P "" - print -P "%B(2) Fluent.%b" - print -P "" - prefixes=("$fluent[@]") print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) prefixes=("$concise[@]"); options+=concise; (( saved_columns += saves )); break;; - 2) prefixes=("$fluent[@]"); options+=fluent; break;; - esac - done - + add_widget 0 flowing -c "%BPrompt Flow%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) Concise.%b" + add_prompt "prefixes=(${(j: :)${(@q)concise}})" + add_widget 0 print -P "%B(2) Fluent.%b" + add_prompt "prefixes=(${(j: :)${(@q)fluent}})" + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) prefixes=("$concise[@]"); options+=concise;; + 2) prefixes=("$fluent[@]"); options+=fluent;; + esac return 0 } function ask_separators() { if [[ $style != (classic|rainbow) || $cap_diamond != 1 ]]; then - (( saved_columns += 5 )) return 0 fi - if [[ $POWERLEVEL9K_MODE == nerdfont-complete && $LINES -lt 26 ]]; then - local nl='' - else - local nl=$'\n' + local extra + add_widget 0 flowing -c "%BPrompt Separators%b" + add_widget 0 print -Pl " separator" "%B(1) Angled.%b /" " /" + add_widget 3 print -P "%B(1) Angled.%b" + add_prompt_n left_sep=$right_triangle right_sep=$left_triangle left_subsep=$right_angle right_subsep=$left_angle + add_widget 0 print + add_widget 2 + add_widget 0 print -P "%B(2) Vertical.%b" + add_prompt left_sep='' right_sep='' left_subsep=$vertical_bar right_subsep=$vertical_bar + if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then + extra+=3 + add_widget 0 print -P "%B(3) Slanted.%b" + add_prompt left_sep=$down_triangle right_sep=$up_triangle left_subsep=$slanted_bar right_subsep=$slanted_bar + extra+=4 + add_widget 0 print -P "%B(4) Round.%b" + add_prompt left_sep=$right_circle right_sep=$left_circle left_subsep=$right_arc right_subsep=$left_arc fi - while true; do - local extra= - clear - flowing -c "%BPrompt Separators%b" - if [[ -n $nl ]]; then - print -P " separator" - print -P "%B(1) Angled.%b /" - print -P " /" - else - print -P "%B(1) Angled.%b" - fi - left_sep=$right_triangle right_sep=$left_triangle left_subsep=$right_angle right_subsep=$left_angle print_prompt - print -P "" - print -P "%B(2) Vertical.%b" - print -n $nl - left_sep='' right_sep='' left_subsep=$vertical_bar right_subsep=$vertical_bar print_prompt - print -P "" - if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then - extra+=3 - print -P "%B(3) Slanted.%b" - print -n $nl - left_sep=$down_triangle right_sep=$up_triangle left_subsep=$slanted_bar right_subsep=$slanted_bar print_prompt - print -P "" - extra+=4 - print -P "%B(4) Round.%b" - print -n $nl - left_sep=$right_circle right_sep=$left_circle left_subsep=$right_arc right_subsep=$left_arc print_prompt - print -P "" - fi - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12${extra}rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) - left_sep=$right_triangle - right_sep=$left_triangle - left_subsep=$right_angle - right_subsep=$left_angle - options+='angled separators' - break - ;; - 2) - left_sep='' - right_sep='' - left_subsep=$vertical_bar - right_subsep=$vertical_bar - options+='vertical separators' - break - ;; - 3) - if [[ $extra == *3* ]]; then - left_sep=$down_triangle - right_sep=$up_triangle - left_subsep=$slanted_bar - right_subsep=$slanted_bar - options+='slanted separators' - break - fi - ;; - 4) - if [[ $extra == *4* ]]; then - left_sep=$right_circle - right_sep=$left_circle - left_subsep=$right_arc - right_subsep=$left_arc - options+='round separators' - break - fi - ;; - esac - done - - prompt_length $left_sep - (( saved_columns += (2 - REPLY) * 2 )) - prompt_length $right_sep - (( saved_columns += (2 - REPLY) * 1 )) + add_widget 0 print -P "(r) Restart from the beginning." + ask 12${extra}r + case $choice in + r) return 1;; + 1) + left_sep=$right_triangle + right_sep=$left_triangle + left_subsep=$right_angle + right_subsep=$left_angle + options+='angled separators' + ;; + 2) + left_sep='' + right_sep='' + left_subsep=$vertical_bar + right_subsep=$vertical_bar + options+='vertical separators' + ;; + 3) + left_sep=$down_triangle + right_sep=$up_triangle + left_subsep=$slanted_bar + right_subsep=$slanted_bar + options+='slanted separators' + ;; + 4) + left_sep=$right_circle + right_sep=$left_circle + left_subsep=$right_arc + right_subsep=$left_arc + options+='round separators' + ;; + esac return 0 } function ask_heads() { if [[ $style != (classic|rainbow) || $POWERLEVEL9K_MODE == ascii ]]; then - (( saved_columns += 6 )) return 0 fi - if [[ $POWERLEVEL9K_MODE == nerdfont-complete && $LINES -lt 26 ]]; then - local nl='' + local extra + add_widget 0 flowing -c "%BPrompt Heads%b" + if (( cap_diamond )); then + add_widget 0 print -Pl " head" "%B(1) Sharp.%b |" " v" + add_widget 3 print -P "%B(1) Sharp.%b" + add_prompt_n left_head=$right_triangle right_head=$left_triangle + add_widget 0 print + add_widget 2 else - local nl=$'\n' + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) Flat.%b" + add_prompt left_head= right_head= fi - while true; do - local extra= - clear - if - flowing -c "%BPrompt Heads%b" - if (( cap_diamond )); then - if [[ -n $nl ]]; then - print -P " head" - print -P "%B(1) Sharp.%b |" - print -P " v" + add_widget 0 print -P "%B(2) Blurred.%b" + add_prompt left_head=$fade_out right_head=$fade_in + if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then + extra+=3 + add_widget 0 print -P "%B(3) Slanted.%b" + add_prompt left_head=$down_triangle right_head=$up_triangle + extra+=4 + add_widget 0 print -P "%B(4) Round.%b" + add_prompt left_head=$right_circle right_head=$left_circle + fi + add_widget 0 print -P "(r) Restart from the beginning." + ask 12${extra}r + case $choice in + r) return 1;; + 1) + if (( cap_diamond )); then + left_head=$right_triangle + right_head=$left_triangle + options+='sharp heads' else - print -P "%B(1) Sharp.%b" + left_head= + right_head= + options+='flat heads' fi - left_head=$right_triangle right_head=$left_triangle print_prompt - else - print -P "" - print -P "%B(1) Flat.%b" - print -P "" - left_head= right_head= print_prompt - fi - print -P "" - print -P "%B(2) Blurred.%b" - print -n $nl - left_head=$fade_out right_head=$fade_in print_prompt - print -P "" - if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then - extra+=3 - print -P "%B(3) Slanted.%b" - print -n $nl - left_head=$down_triangle right_head=$up_triangle print_prompt - print -P "" - extra+=4 - print -P "%B(4) Round.%b" - print -n $nl - left_head=$right_circle right_head=$left_circle print_prompt - print -P "" - fi - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12${extra}rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) - if (( cap_diamond )); then - left_head=$right_triangle - right_head=$left_triangle - options+='sharp heads' - else - left_head= - right_head= - options+='flat heads' - fi - break - ;; - 2) - left_head=$fade_out - right_head=$fade_in - options+='blurred heads' - break - ;; - 3) - if [[ $extra == *3* ]]; then - left_head=$down_triangle - right_head=$up_triangle - options+='slanted heads' - break - fi - ;; - 4) - if [[ $extra == *4* ]]; then - left_head=$right_circle - right_head=$left_circle - options+='round heads' - break - fi - ;; - esac - done - - prompt_length $left_head - (( saved_columns += 3 - REPLY )) - prompt_length $right_head - (( saved_columns += 3 - REPLY )) + ;; + 2) + left_head=$fade_out + right_head=$fade_in + options+='blurred heads' + ;; + 3) + left_head=$down_triangle + right_head=$up_triangle + options+='slanted heads' + ;; + 4) + left_head=$right_circle + right_head=$left_circle + options+='round heads' + ;; + esac return 0 } +function print_tail_marker() { + local label='(1) Flat.' + local -i n='wizard_columns - 7' + local -i m=$((n - $#label)) + print -P "${(l:$n:: :)}tail" + print -P "%B$label%b${(l:$m:: :)} |" + print -P "${(l:$n:: :)} v" +} + function ask_tails() { if [[ $style != (classic|rainbow) || $POWERLEVEL9K_MODE == ascii ]]; then - (( saved_columns += 6 )) return 0 fi - if [[ $POWERLEVEL9K_MODE == nerdfont-complete && $LINES -lt 31 ]]; then - local nl='' - else - local nl=$'\n' - fi - while true; do - local extra= - clear - flowing -c "%BPrompt Tails%b" - print -n $nl - print -P "%B(1) Flat.%b" - print -n $nl - left_tail='' right_tail='' print_prompt - print -P "" - print -P "%B(2) Blurred.%b" - print -n $nl - left_tail=$fade_in right_tail=$fade_out print_prompt - print -P "" - if (( cap_diamond )); then - extra+=3 - print -P "%B(3) Sharp.%b" - print -n $nl - left_tail=$left_triangle right_tail=$right_triangle print_prompt - print -P "" - if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then - extra+=4 - print -P "%B(4) Slanted.%b" - print -n $nl - left_tail=$up_triangle right_tail=$down_triangle print_prompt - print -P "" - if (( LINES >= 25 )); then - extra+=5 - print -P "%B(5) Round.%b" - print -n $nl - left_tail=$left_circle right_tail=$right_circle print_prompt - print -P "" - fi - fi + local extra + add_widget 0 flowing -c "%BPrompt Tails%b" + add_widget 0 print_tail_marker + add_widget 3 print -P "%B(1) Flat.%b" + add_prompt_n left_tail='' right_tail='' + add_widget 0 print + add_widget 2 + add_widget 0 print -P "%B(2) Blurred.%b" + add_prompt left_tail=$fade_in right_tail=$fade_out + if (( cap_diamond )); then + extra+=3 + add_widget 0 print -P "%B(3) Sharp.%b" + add_prompt left_tail=$left_triangle right_tail=$right_triangle + if [[ $POWERLEVEL9K_MODE == nerdfont-complete ]]; then + extra+=4 + add_widget 0 print -P "%B(4) Slanted.%b" + add_prompt left_tail=$up_triangle right_tail=$down_triangle + extra+=5 + add_widget 0 print -P "%B(5) Round.%b" + add_prompt left_tail=$left_circle right_tail=$right_circle fi - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12${extra}rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) left_tail=''; right_tail=''; options+='flat tails'; break;; - 2) left_tail=$fade_in; right_tail=$fade_out; options+='blurred tails'; break;; - 3) - if [[ $extra == *3* ]]; then - left_tail=$left_triangle - right_tail=$right_triangle - options+='sharp tails' - break - fi - ;; - 4) - if [[ $extra == *4* ]]; then - left_tail=$up_triangle - right_tail=$down_triangle - options+='slanted tails' - break - fi - ;; - 5) - if [[ $extra == *5* ]]; then - left_tail=$left_circle - right_tail=$right_circle - options+='round tails' - break - fi - ;; - esac - done - - prompt_length $left_tail - (( saved_columns += 3 - REPLY )) - prompt_length $right_tail - (( saved_columns += 3 - REPLY )) + fi + add_widget 0 print -P "(r) Restart from the beginning." + ask 12${extra}r + case $choice in + r) return 1;; + 1) left_tail=''; right_tail=''; options+='flat tails';; + 2) left_tail=$fade_in; right_tail=$fade_out; options+='blurred tails';; + 3) + left_tail=$left_triangle + right_tail=$right_triangle + options+='sharp tails' + ;; + 4) + left_tail=$up_triangle + right_tail=$down_triangle + options+='slanted tails' + ;; + 5) + left_tail=$left_circle + right_tail=$right_circle + options+='round tails' + ;; + esac return 0 } function ask_num_lines() { - while true; do - clear - flowing -c "%BPrompt Height%b" - print -P "" - print -P "%B(1) One line.%b" - print -P "" - num_lines=1 print_prompt - print -P "" - print -P "%B(2) Two lines.%b" - print -P "" - num_lines=2 print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) num_lines=1; options+='1 line'; break;; - 2) num_lines=2; options+='2 lines'; break;; - esac - done - + add_widget 0 flowing -c "%BPrompt Height%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) One line.%b" + add_prompt num_lines=1 + add_widget 0 print -P "%B(2) Two lines.%b" + add_prompt num_lines=2 + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) num_lines=1; options+='1 line';; + 2) num_lines=2; options+='2 lines';; + esac return 0 } @@ -1506,163 +1327,121 @@ function ask_gap_char() { local dot='·' local dash='─' fi - while true; do - clear - flowing -c "%BPrompt Connection%b" - print -P "" - print -P "%B(1) Disconnected.%b" - print -P "" - gap_char=" " print_prompt - print -P "" - print -P "%B(2) Dotted.%b" - print -P "" - gap_char=$dot print_prompt - print -P "" - print -P "%B(3) Solid.%b" - print -P "" - gap_char=$dash print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [123rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) gap_char=" "; options+=disconnected; break;; - 2) gap_char=$dot; options+=dotted; break;; - 3) gap_char=$dash; options+=solid; break;; - esac - done - + add_widget 0 flowing -c "%BPrompt Connection%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) Disconnected.%b" + add_prompt gap_char=" " + add_widget 0 print -P "%B(2) Dotted.%b" + add_prompt gap_char=$dot + add_widget 0 print -P "%B(3) Solid.%b" + add_prompt gap_char=$dash + add_widget 0 print -P "(r) Restart from the beginning." + ask 123r + case $choice in + r) return 1;; + 1) gap_char=" "; options+=disconnected;; + 2) gap_char=$dot; options+=dotted;; + 3) gap_char=$dash; options+=solid;; + esac return 0 } function ask_frame() { if [[ $style != (classic|rainbow|lean*) || $num_lines != 2 || $POWERLEVEL9K_MODE == ascii ]]; then - (( saved_columns += 4 )) return 0 fi - - (( LINES >= 26 )) && local nl=$'\n' || local nl='' - while true; do - clear - flowing -c "%BPrompt Frame%b" - print -n $nl - print -P "%B(1) No frame.%b" - print -n $nl - left_frame=0 right_frame=0 print_prompt - print -P "" - print -P "%B(2) Left.%b" - print -n $nl - left_frame=1 right_frame=0 print_prompt - print -P "" - print -P "%B(3) Right.%b" - print -n $nl - left_frame=0 right_frame=1 print_prompt - print -P "" - print -P "%B(4) Full.%b" - print -n $nl - left_frame=1 right_frame=1 print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [1234rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) left_frame=0; right_frame=0; options+='no frame'; break;; - 2) left_frame=1; right_frame=0; options+='left frame'; break;; - 3) left_frame=0; right_frame=1; options+='right frame'; break;; - 4) left_frame=1; right_frame=1; options+='full frame'; break;; - esac - done - - (( left_frame )) || (( saved_columns += 2 )) - (( right_frame )) || (( saved_columns += 2 )) + add_widget 0 flowing -c "%BPrompt Frame%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) No frame.%b" + add_prompt left_frame=0 right_frame=0 + add_widget 0 print -P "%B(2) Left.%b" + add_prompt left_frame=1 right_frame=0 + add_widget 0 print -P "%B(3) Right.%b" + add_prompt left_frame=0 right_frame=1 + add_widget 0 print -P "%B(4) Full.%b" + add_prompt left_frame=1 right_frame=1 + add_widget 0 print -P "(r) Restart from the beginning." + ask 1234r + case $key in + r) return 1;; + 1) left_frame=0; right_frame=0; options+='no frame';; + 2) left_frame=1; right_frame=0; options+='left frame';; + 3) left_frame=0; right_frame=1; options+='right frame';; + 4) left_frame=1; right_frame=1; options+='full frame';; + esac return 0 } function ask_empty_line() { - while true; do - clear - flowing -c "%BPrompt Spacing%b" - print -P "" - print -P "%B(1) Compact.%b" - print -P "" - print_prompt - print_prompt - print -P "" - print -P "%B(2) Sparse.%b" - print -P "" - print_prompt - print -P "" - print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [12rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) empty_line=0; options+='compact'; break;; - 2) empty_line=1; options+='sparse'; break;; - esac - done - + add_widget 0 flowing -c "%BPrompt Spacing%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(1) Compact.%b" + add_widget 0 print + add_widget 1 + add_widget 0 print_prompt + add_widget 0 print_prompt + add_widget 0 print + add_widget 2 + add_widget 0 print -P "%B(2) Sparse.%b" + add_widget 0 print + add_widget 1 + add_widget 0 print_prompt + add_widget 0 print + add_widget 0 print_prompt + add_widget 0 print + add_widget 2 + add_widget 0 print -P "(r) Restart from the beginning." + ask 12r + case $choice in + r) return 1;; + 1) empty_line=0; options+='compact';; + 2) empty_line=1; options+='sparse';; + esac return 0 } +function print_instant_prompt_link() { + local link='https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt' + (( wizard_columns < $#link )) && return + print + flowing -c "$(href $link)" +} + function ask_instant_prompt() { if ! is-at-least 5.4; then instant_prompt=off return 0 fi - if (( LINES < 24 )); then - local nl='' - else - local nl=$'\n' - fi - while true; do - clear - flowing -c "%BInstant Prompt Mode%b" - print -n $nl - flowing -c "$(href 'https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt')" - print -P "" - flowing +c -i 5 "%B(1) Off.%b" Disable instant prompt. Choose this if you\'ve tried instant \ - prompt and found it incompatible with your zsh configuration files. - print -n $nl - flowing +c -i 5 "%B(2) Quiet.%b" Enable instant prompt and %Bdon\'t print warnings%b when \ - detecting console output during zsh initialization. Choose this if you\'ve read and \ - understood the documentation linked above. - print -n $nl - flowing +c -i 5 "%B(3) Verbose.%b" Enable instant prompt and %Bprint a warning%b when \ - detecting console output during zsh initialization. %BChoose this if you\'ve never tried \ - instant prompt, haven\'t seen the warning, or if you are unsure what this all means%b. - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [123rq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - 1) instant_prompt=off; options+=instant_prompt=off; break;; - 2) instant_prompt=quiet; options+=instant_prompt=quiet; break;; - 3) instant_prompt=verbose; options+=instant_prompt=verbose; break;; - esac - done - + add_widget 0 flowing -c "%BInstant Prompt Mode%b" + add_widget 0 print_instant_prompt_link + add_widget 1 + add_widget 0 print + add_widget 2 + add_widget 0 flowing +c -i 5 "%B(1) Off.%b" Disable instant prompt. Choose this if you\'ve \ + tried instant prompt and found it incompatible with your zsh configuration files. + add_widget 0 print + add_widget 1 + add_widget 0 flowing +c -i 5 "%B(2) Quiet.%b" Enable instant prompt and %Bdon\'t print \ + warnings%b when detecting console output during zsh initialization. Choose this if you\'ve \ + read and understood instant prompt documentation. + add_widget 0 print + add_widget 1 + add_widget 0 flowing +c -i 5 "%B(3) Verbose.%b" Enable instant prompt and %Bprint a warning%b \ + when detecting console output during zsh initialization. %BChoose this if you\'ve never tried \ + instant prompt, haven\'t seen the warning, or if you are unsure what this all means%b. + add_widget 0 print + add_widget 2 + add_widget 0 print -P "(r) Restart from the beginning." + ask 123r + case $choice in + r) return 1;; + 1) instant_prompt=off; options+=instant_prompt=off;; + 2) instant_prompt=quiet; options+=instant_prompt=quiet;; + 3) instant_prompt=verbose; options+=instant_prompt=verbose;; + esac return 0 } @@ -1672,52 +1451,37 @@ function ask_transient_prompt() { [[ $style == pure ]] && p=$pure_color[magenta] [[ $style == lean_8colors ]] && p=2 p="%F{$p}$prompt_char%f" - while true; do - clear - flowing -c "%BEnable Transient Prompt?%b" - print -P "" - print -P "%B(y) Yes.%b" - if (( LINES >= 25 || num_lines == 1 )); then - print -P "" - print -P "${(pl:$prompt_indent:: :)}$p %2Fgit%f pull" - elif (( LINES < 23 )); then - print -P "" - else - print -P "${(pl:$prompt_indent:: :)}$p %2Fgit%f pull" - fi - print -P "${(pl:$prompt_indent:: :)}$p %2Fgit%f branch x" - (( empty_line )) && echo - buffer="%2Fgit%f checkout x█" print_prompt - print -P "" - print -P "%B(n) No.%b" - if (( LINES >= 25 || num_lines == 1 )); then - print -P "" - buffer="%2Fgit%f pull" print_prompt - (( empty_line )) && echo - elif (( LINES < 23 )); then - print -P "" - else - buffer="%2Fgit%f pull" print_prompt - (( empty_line )) && echo - fi - buffer="%2Fgit%f branch x" print_prompt - (( empty_line )) && echo - buffer="%2Fgit%f checkout x█" print_prompt - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [ynrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) transient_prompt=1; options+=transient_prompt; break;; - n) transient_prompt=0; break;; - esac - done - + add_widget 0 flowing -c "%BEnable Transient Prompt?%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "%B(y) Yes.%b" + add_widget 0 print + add_widget 1 + add_widget 0 print -P "${(pl:$prompt_indent:: :)}$p %2Fgit%f pull" + add_widget 3 + add_widget 0 print -P "${(pl:$prompt_indent:: :)}$p %2Fgit%f branch x" + (( empty_line )) && add_widget 0 print + add_prompt_n buffer="%2Fgit%f checkout x$cursor" + add_widget 0 print + add_widget 2 + add_widget 0 print -P "%B(n) No.%b" + add_widget 0 print + add_widget 1 + add_widget 0 buffer="%2Fgit%f pull" print_prompt + add_widget 3 + (( empty_line )) && { add_widget 0 print; add_widget 3 } + add_prompt_n buffer="%2Fgit%f branch x" + (( empty_line )) && add_widget 0 print + add_prompt_n buffer="%2Fgit%f checkout x$cursor" + add_widget 0 print + add_widget 2 + add_widget 0 print -P "(r) Restart from the beginning." + ask ynr + case $choice in + r) return 1;; + y) transient_prompt=1; options+=transient_prompt;; + n) transient_prompt=0;; + esac return 0 } @@ -1727,31 +1491,21 @@ function ask_config_overwrite() { if [[ ! -e $__p9k_cfg_path ]]; then return 0 fi - while true; do - clear - flowing -c "Powerlevel10k config file already exists." - flowing -c "%BOverwrite" "%b%2F${__p9k_cfg_path_u//\\/\\\\}%f%B?%b" - print -P "" - print -P "%B(y) Yes.%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [yrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - y) - config_backup="$(mktemp ${TMPDIR:-/tmp}/$__p9k_cfg_basename.XXXXXXXXXX)" || quit -c - cp $__p9k_cfg_path $config_backup || quit -c - config_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)config_backup:t} - break - ;; - esac - done - + add_widget 0 flowing -c Powerlevel10k config file already exists. + add_widget 0 flowing -c "%BOverwrite" "%b%2F${__p9k_cfg_path_u//\\/\\\\}%f%B?%b" + add_widget 0 print -P "" + add_widget 0 print -P "%B(y) Yes.%b" + add_widget 0 print -P "" + add_widget 0 print -P "(r) Restart from the beginning." + ask yr + case $choice in + r) return 1;; + y) + config_backup="$(mktemp ${TMPDIR:-/tmp}/$__p9k_cfg_basename.XXXXXXXXXX)" || quit -c + cp $__p9k_cfg_path $config_backup || quit -c + config_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)config_backup:t} + ;; + esac return 0 } @@ -1799,62 +1553,52 @@ function ask_zshrc_edit() { (( zshrc_has_cfg && zshrc_has_instant_prompt )) && return fi - while true; do - clear - flowing -c "%BApply changes to %b%2F${__p9k_zshrc_u//\\/\\\\}%f%B?%b" - print -P "" - local modifiable=y - if [[ -e $__p9k_zshrc && ! -w $__p9k_zshrc ]]; then - local -a stat - zstat -A stat +uid -- $__p9k_zshrc || quit -c - if (( stat[1] == EUID )); then - flowing -c %3FNOTE:%f %2F${__p9k_zshrc_u//\\/\\\\}%f %3Fis readonly.%f - else - modifiable= - flowing -c \ - %3FWARNING:%f %2F${__p9k_zshrc_u//\\/\\\\}%f %3Fis readonly and \ - not owned by the user. Cannot modify it.%f - fi - print -P "" - fi - if [[ $modifiable == y ]]; then - print -P "%B(y) Yes (recommended).%b" + add_widget 0 flowing -c %BApply changes to "%b%2F${__p9k_zshrc_u//\\/\\\\}%f%B?%b" + add_widget 0 print -P "" + add_widget 1 + local modifiable=y + if [[ -e $__p9k_zshrc && ! -w $__p9k_zshrc ]]; then + local -a stat + zstat -A stat +uid -- $__p9k_zshrc || quit -c + if (( stat[1] == EUID )); then + add_widget 0 flowing -c %3FNOTE:%f %2F${__p9k_zshrc_u//\\/\\\\}%f %3Fis readonly.%f else - print -P "%1F(y) Yes (disabled).%f" + modifiable= + add_widget 0 flowing -c \ + %3FWARNING:%f %2F${__p9k_zshrc_u//\\/\\\\}%f %3Fis readonly and \ + not owned by the user. Cannot modify it.%f fi - print -P "" - print -P "%B(n) No. I know which changes to apply and will do it myself.%b" - print -P "" - print -P "(r) Restart from the beginning." - print -P "(q) Quit and do nothing." - print -P "" - - local key= - read -k key${(%):-"?%BChoice [${modifiable}nrq]: %b"} || quit -c - case $key in - q) quit;; - r) return 1;; - n) return 0;; - y) - [[ $modifiable == y ]] || continue - write_zshrc=1 - if [[ -n $zshrc_content ]]; then - zshrc_backup="$(mktemp ${TMPDIR:-/tmp}/.zshrc.XXXXXXXXXX)" || quit -c - cp -p $__p9k_zshrc $zshrc_backup || quit -c - local -i writable=1 - if [[ ! -w $zshrc_backup ]]; then - chmod u+w -- $zshrc_backup || quit -c - writable=0 - fi - print -r -- $zshrc_content >$zshrc_backup || quit -c - (( writable )) || chmod u-w -- $zshrc_backup || quit -c - zshrc_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)zshrc_backup:t} + add_widget 0 print -P "" + fi + if [[ $modifiable == y ]]; then + add_widget 0 print -P "%B(y) Yes (recommended).%b" + else + add_widget 0 print -P "%1F(y) Yes (disabled).%f" + fi + add_widget 0 print -P "" + add_widget 0 flowing +c -i 5 "%B(n) No." I know which changes to apply and will do it myself.%b + add_widget 0 print -P "" + add_widget 0 print -P "(r) Restart from the beginning." + ask ${modifiable}nr + case $choice in + r) return 1;; + n) return 0;; + y) + write_zshrc=1 + if [[ -n $zshrc_content ]]; then + zshrc_backup="$(mktemp ${TMPDIR:-/tmp}/.zshrc.XXXXXXXXXX)" || quit -c + cp -p $__p9k_zshrc $zshrc_backup || quit -c + local -i writable=1 + if [[ ! -w $zshrc_backup ]]; then + chmod u+w -- $zshrc_backup || quit -c + writable=0 fi - break - ;; - esac - done - + print -r -- $zshrc_content >$zshrc_backup || quit -c + (( writable )) || chmod u-w -- $zshrc_backup || quit -c + zshrc_backup_u=${${TMPDIR:+\$TMPDIR}:-/tmp}/${(q-)zshrc_backup:t} + fi + ;; + esac return 0 } @@ -2170,8 +1914,7 @@ while true; do local POWERLEVEL9K_MODE= POWERLEVEL9K_ICON_PADDING=moderate style= config_backup= config_backup_u= local gap_char=' ' prompt_char='❯' down_triangle='\uE0BC' up_triangle='\uE0BA' slanted_bar='\u2571' local left_subsep= right_subsep= left_tail= right_tail= left_head= right_head= time= - local -i num_lines=0 empty_line=0 color=2 left_frame=1 right_frame=1 transient_prompt=0 - local -i wizard_columns=$((COLUMNS < 88 ? COLUMNS : 88)) saved_columns=0 + local -i num_lines=2 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_lock=0 cap_arrow=0 local -a extra_icons=('' '' '') local -a frame_color=(244 242 240 238) @@ -2285,12 +2028,8 @@ while true; do break done -if (( $+terminfo[smcup] && $+terminfo[rmcup] )); then - echoti rmcup - print -else - clear -fi +restore_screen +print flowing +c New config: "%B${__p9k_cfg_path_u//\\/\\\\}%b." if [[ -n $config_backup ]]; then @@ -2306,3 +2045,10 @@ change_zshrc || return print -rP "" flowing +c File feature requests and bug reports at "$(href https://github.com/romkatv/powerlevel10k/issues)" print -rP "" + +} always { + consume_input + stty echo 2>/dev/null + show_cursor + restore_screen +}