wizard: better text overflow

pull/203/head
romkatv 5 years ago
parent d6041f53aa
commit 37dc2ba5e2

@ -128,7 +128,18 @@ function href() {
print -r -- $'%{\e]8;;'${1//\%/%%}$'\a%}'${1//\%/%%}$'%{\e]8;;\a%}' print -r -- $'%{\e]8;;'${1//\%/%%}$'\a%}'${1//\%/%%}$'%{\e]8;;\a%}'
} }
function centered() { function flowing() {
local opt
local -i centered indentation
while getopts 'ci:' opt; do
case $opt in
i) indentation=$OPTARG;;
c) centered=1;;
+c) centered=0;;
\?) exit 1;;
esac
done
shift $((OPTIND-1))
local line word lines=() local line word lines=()
for word in "$@"; do for word in "$@"; do
local n=$(prompt_length ${(g::):-"$line $word"}) local n=$(prompt_length ${(g::):-"$line $word"})
@ -136,13 +147,17 @@ function centered() {
[[ -z $line ]] || lines+=$line [[ -z $line ]] || lines+=$line
line= line=
fi fi
[[ -z $line ]] || line+=' ' if [[ -n $line ]]; then
line+=' '
elif (( $#lines )); then
line=${(pl:$indentation:: :)}
fi
line+=$word line+=$word
done done
[[ -z $line ]] || lines+=$line [[ -z $line ]] || lines+=$line
for line in $lines; do for line in $lines; do
local n=$(prompt_length ${(g::)line}) local n=$(prompt_length ${(g::)line})
(( n < wizard_columns )) && print -n -- ${(pl:$(((wizard_columns - n) / 2)):: :)} (( centered && n < wizard_columns )) && print -n -- ${(pl:$(((wizard_columns - n) / 2)):: :)}
print -P -- $line print -P -- $line
done done
} }
@ -184,19 +199,19 @@ function ask_diamond() {
while true; do while true; do
clear clear
if (( force )); then if (( force )); then
centered This is %4FPowerlevel10k configuration wizard%f. \ flowing -c This is %4FPowerlevel10k configuration wizard%f. \
It will ask you a few questions and configure your prompt. It will ask you a few questions and configure your prompt.
else else
centered This is %4FPowerlevel10k configuration wizard%f. \ flowing -c This is %4FPowerlevel10k configuration wizard%f. \
You are seeing it because you haven\'t defined any \ You are seeing it because you haven\'t defined any \
Powerlevel10k configuration options. It will ask \ Powerlevel10k configuration options. It will ask \
you a few questions and configure your prompt. you a few questions and configure your prompt.
fi fi
print -P "" print -P ""
centered "%BDoes this look like a %b%2Fdiamond%f%B (rotated square)?%b" flowing -c "%BDoes this look like a %b%2Fdiamond%f%B (rotated square)?%b"
centered "reference: $(href https://graphemica.com/%E2%97%86)" flowing -c "reference: $(href https://graphemica.com/%E2%97%86)"
print -P "" print -P ""
centered "---> \uE0B2\uE0B0 <---" flowing -c -- "---> \uE0B2\uE0B0 <---"
print -P "" print -P ""
print -P "%B(y) Yes.%b" print -P "%B(y) Yes.%b"
print -P "" print -P ""
@ -218,11 +233,11 @@ function ask_diamond() {
function ask_lock() { function ask_lock() {
while true; do while true; do
clear clear
[[ -n $2 ]] && centered "$2" [[ -n $2 ]] && flowing -c "$2"
centered "%BDoes this look like a %b%2Flock%f%B?%b" flowing -c "%BDoes this look like a %b%2Flock%f%B?%b"
centered "reference: $(href https://fontawesome.com/icons/lock)" flowing -c "reference: $(href https://fontawesome.com/icons/lock)"
print -P "" print -P ""
centered "---> $1 <---" flowing -c -- "---> $1 <---"
print -P "" print -P ""
print -P "%B(y) Yes.%b" print -P "%B(y) Yes.%b"
print -P "" print -P ""
@ -246,10 +261,10 @@ function ask_lock() {
function ask_python() { function ask_python() {
while true; do while true; do
clear clear
centered "%BDoes this look like a %b%2FPython logo%f%B?%b" flowing -c "%BDoes this look like a %b%2FPython logo%f%B?%b"
centered "reference: $(href https://fontawesome.com/icons/python)" flowing -c "reference: $(href https://fontawesome.com/icons/python)"
print -P "" print -P ""
centered "---> \uE63C <---" flowing -c -- "---> \uE63C <---"
print -P "" print -P ""
print -P "%B(y) Yes.%b" print -P "%B(y) Yes.%b"
print -P "" print -P ""
@ -273,10 +288,10 @@ function ask_python() {
function ask_debian() { function ask_debian() {
while true; do while true; do
clear clear
centered "%BDoes this look like a %b%2FDebian logo%f%B (swirl/spiral)?%b" flowing -c "%BDoes this look like a %b%2FDebian logo%f%B (swirl/spiral)?%b"
centered "reference: $(href https://debian.org/logos/openlogo-nd.svg)" flowing -c "reference: $(href https://debian.org/logos/openlogo-nd.svg)"
print -P "" print -P ""
centered "---> \uF306 <---" flowing -c -- "---> \uF306 <---"
print -P "" print -P ""
print -P "%B(y) Yes.%b" print -P "%B(y) Yes.%b"
print -P "" print -P ""
@ -314,11 +329,11 @@ function ask_narrow_icons() {
text+="%3F${icons[RAM_ICON]// }%fX" text+="%3F${icons[RAM_ICON]// }%fX"
while true; do while true; do
clear clear
centered "%BDo all these icons %b%2Ffit between the crosses%f%B?%b" flowing -c "%BDo all these icons %b%2Ffit between the crosses%f%B?%b"
print -P "" print -P ""
centered "---> $text <---" flowing -c -- "---> $text <---"
print -P "" print -P ""
print -P "%B(y) Yes. Icons are very close to the crosses but there is %b%2Fno overlap%f%B.%b" 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 ""
print -P "%B(n) No. Some icons %b%2Foverlap%f%B neighbouring crosses.%b" print -P "%B(n) No. Some icons %b%2Foverlap%f%B neighbouring crosses.%b"
print -P "" print -P ""
@ -340,7 +355,7 @@ function ask_narrow_icons() {
function ask_style() { function ask_style() {
while true; do while true; do
clear clear
centered "%BPrompt Style%b" flowing -c "%BPrompt Style%b"
print -P "" print -P ""
print -P "%B(1) Lean.%b" print -P "%B(1) Lean.%b"
print -P "" print -P ""
@ -374,7 +389,7 @@ function ask_color() {
fi fi
while true; do while true; do
clear clear
centered "%BPrompt Color%b" flowing -c "%BPrompt Color%b"
print -n $nl print -n $nl
print -P "%B(1) Lightest.%b" print -P "%B(1) Lightest.%b"
print -n $nl print -n $nl
@ -417,7 +432,7 @@ function ask_time() {
while true; do while true; do
clear clear
centered "%BShow current time?%b" flowing -c "%BShow current time?%b"
print -P "" print -P ""
print -P "%B(y) Yes.%b" print -P "%B(y) Yes.%b"
print -P "" print -P ""
@ -514,7 +529,7 @@ function ask_extra_icons() {
local many=("$os_icon" "$dir_icon " "$vcs_icon $branch_icon " "$duration_icon " "$time_icon ") local many=("$os_icon" "$dir_icon " "$vcs_icon $branch_icon " "$duration_icon " "$time_icon ")
while true; do while true; do
clear clear
centered "%BIcons%b" flowing -c "%BIcons%b"
print -P "" print -P ""
print -P "%B(1) Few icons.%b" print -P "%B(1) Few icons.%b"
print -P "" print -P ""
@ -549,7 +564,7 @@ function ask_prefixes() {
fi fi
while true; do while true; do
clear clear
centered "%BPrompt Flow%b" flowing -c "%BPrompt Flow%b"
print -P "" print -P ""
print -P "%B(1) Concise.%b" print -P "%B(1) Concise.%b"
print -P "" print -P ""
@ -581,7 +596,7 @@ function ask_separators() {
while true; do while true; do
local extra= local extra=
clear clear
centered "%BPrompt Separators%b" flowing -c "%BPrompt Separators%b"
print -P " separator" print -P " separator"
print -P "%B(1) Angled.%b /" print -P "%B(1) Angled.%b /"
print -P " /" print -P " /"
@ -644,7 +659,7 @@ function ask_heads() {
while true; do while true; do
local extra= local extra=
clear clear
centered "%BPrompt Heads%b" flowing -c "%BPrompt Heads%b"
print -P " head" print -P " head"
print -P "%B(1) Sharp.%b |" print -P "%B(1) Sharp.%b |"
print -P " v" print -P " v"
@ -697,7 +712,7 @@ function ask_tails() {
while true; do while true; do
local extra= local extra=
clear clear
centered "%BPrompt Tails%b" flowing -c "%BPrompt Tails%b"
print -n $nl print -n $nl
print -P "%B(1) Flat.%b" print -P "%B(1) Flat.%b"
print -n $nl print -n $nl
@ -755,7 +770,7 @@ function ask_tails() {
function ask_num_lines() { function ask_num_lines() {
while true; do while true; do
clear clear
centered "%BPrompt Height%b" flowing -c "%BPrompt Height%b"
print -P "" print -P ""
print -P "%B(1) One line.%b" print -P "%B(1) One line.%b"
print -P "" print -P ""
@ -786,7 +801,7 @@ function ask_gap_char() {
fi fi
while true; do while true; do
clear clear
centered "%BPrompt Connection%b" flowing -c "%BPrompt Connection%b"
print -P "" print -P ""
print -P "%B(1) Disconnected.%b" print -P "%B(1) Disconnected.%b"
print -P "" print -P ""
@ -824,7 +839,7 @@ function ask_frame() {
(( LINES >= 26 )) && local nl=$'\n' || local nl='' (( LINES >= 26 )) && local nl=$'\n' || local nl=''
while true; do while true; do
clear clear
centered "%BPrompt Frame%b" flowing -c "%BPrompt Frame%b"
print -n $nl print -n $nl
print -P "%B(1) No frame.%b" print -P "%B(1) No frame.%b"
print -n $nl print -n $nl
@ -862,7 +877,7 @@ function ask_frame() {
function ask_empty_line() { function ask_empty_line() {
while true; do while true; do
clear clear
centered "%BPrompt Spacing%b" flowing -c "%BPrompt Spacing%b"
print -P "" print -P ""
print -P "%B(1) Compact.%b" print -P "%B(1) Compact.%b"
print -P "" print -P ""
@ -893,7 +908,7 @@ function ask_empty_line() {
function ask_confirm() { function ask_confirm() {
while true; do while true; do
clear clear
centered "%BLooks good?%b" flowing -c "%BLooks good?%b"
print -P "" print -P ""
print_prompt print_prompt
(( empty_line )) && print -P "" (( empty_line )) && print -P ""
@ -923,8 +938,8 @@ function ask_config_overwrite() {
fi fi
while true; do while true; do
clear clear
centered "Powerlevel10k config file already exists." flowing -c "Powerlevel10k config file already exists."
centered "%BOverwrite %b%2F${__p9k_cfg_path_u//\\/\\\\}%f%B?%b" flowing -c "%BOverwrite" "%b%2F${__p9k_cfg_path_u//\\/\\\\}%f%B?%b"
print -P "" print -P ""
print -P "%B(y) Yes.%b" print -P "%B(y) Yes.%b"
print -P "" print -P ""

Loading…
Cancel
Save