Refactor configuration wizard

This commit is contained in:
Ilan Cosman 2020-05-18 16:17:50 -07:00
parent a35fc7311c
commit 9b34974d15
28 changed files with 333 additions and 356 deletions

View File

@ -0,0 +1,33 @@
function finish
_title 'Overwrite lean config?'
_option y 'Yes'
printf '%b' '\n\n'
_option n 'No'
printf '%b' '\n\n'
switch (_menu 'Choice' y/n)
case y
set -U lean_right_prompt_items 'status' 'cmd_duration' 'context' 'jobs'
if test -z $lean_time_format
set -a lean_right_prompt_items 'time'
end
set -l vars lean_{ \
newline, \
left_prompt_items, \
prompt_connection_color, prompt_connection_icon, \
time_format, \
}
for var in $vars
set -l fakeVar "fake_$var"
set -U $var $$fakeVar
end
case n
end
_quit
end

View File

@ -0,0 +1,30 @@
function prompt_connection
_title 'Prompt Connection'
_option 1 'Disconnected'
_display_prompt fake_lean_prompt_connection_icon ' '
_option 2 'Dotted'
_display_prompt fake_lean_prompt_connection_icon '·'
_option 3 'Solid'
_display_prompt fake_lean_prompt_connection_icon '─'
_display_restart_and_quit
switch (_menu 'Choice' 1/2/3/r/q)
case 1
set -g fake_lean_prompt_connection_icon ' '
_next_choice 'prompt_spacing'
case 2
set -g fake_lean_prompt_connection_icon '·'
_next_choice 'prompt_connection_color'
case 3
set -g fake_lean_prompt_connection_icon '─'
_next_choice 'prompt_connection_color'
case r
_begin
case q
_quit
end
end

View File

@ -0,0 +1,36 @@
function prompt_connection_color
_title 'Connection Color'
_option 1 'Lightest'
_display_prompt fake_lean_prompt_connection_color 808080
_option 2 'Light'
_display_prompt fake_lean_prompt_connection_color 6C6C6C
_option 3 'Dark'
_display_prompt fake_lean_prompt_connection_color 585858
_option 4 'Darkest'
_display_prompt fake_lean_prompt_connection_color 444444
_display_restart_and_quit
switch (_menu 'Choice' 1/2/3/4/r/q)
case 1
set -g fake_lean_prompt_connection_color 808080
_next_choice 'prompt_spacing'
case 2
set -g fake_lean_prompt_connection_color 6C6C6C
_next_choice 'prompt_spacing'
case 3
set -g fake_lean_prompt_connection_color 585858
_next_choice 'prompt_spacing'
case 4
set -g fake_lean_prompt_connection_color 444444
_next_choice 'prompt_spacing'
case r
_begin
case q
_quit
end
end

View File

@ -0,0 +1,27 @@
function prompt_height
_title 'Prompt Height?'
_option 1 'One line'
set -g fake_lean_left_prompt_items 'pwd' 'git_prompt' 'prompt_char'
# fake_lean_count_left_prompt_height
_display_prompt
_option 2 'Two lines'
set -g fake_lean_left_prompt_items 'pwd' 'git_prompt' 'newline' 'prompt_char'
_display_prompt
_display_restart_and_quit
switch (_menu 'Choice' 1/2/r/q)
case 1
set -g fake_lean_left_prompt_items 'pwd' 'git_prompt' 'prompt_char'
_next_choice 'prompt_spacing'
case 2
set -g fake_lean_left_prompt_items 'pwd' 'git_prompt' 'newline' 'prompt_char'
_next_choice 'prompt_connection'
case r
_begin
case q
_quit
end
end

View File

@ -0,0 +1,28 @@
function prompt_spacing
_title 'Prompt Spacing'
_option 1 'Compact'
_display_prompt fake_lean_newline true
_cursor_up 1
_display_prompt fake_lean_newline false
_option 2 'Sparse'
_display_prompt fake_lean_newline true
_cursor_up 1
_display_prompt fake_lean_newline true
_display_restart_and_quit
switch (_menu 'Choice' 1/2/r/q)
case 1
set -g fake_lean_newline false
_next_choice 'finish'
case 2
set -g fake_lean_newline true
_next_choice 'finish'
case r
_begin
case q
_quit
end
end

View File

@ -0,0 +1,30 @@
function show_time
_title 'Show current time?'
_option 1 'No'
_display_prompt fake_lean_time_format ''
_option 2 '24-hour format'
_display_prompt fake_lean_time_format '%T'
_option 3 '12-hour format'
_display_prompt fake_lean_time_format '%r'
_display_restart_and_quit
switch (_menu 'Choice' 1/2/3/r/q)
case 1
set -g fake_lean_time_format ''
_next_choice 'prompt_height'
case 2
set -g fake_lean_time_format '%T'
_next_choice 'prompt_height'
case 3
set -g fake_lean_time_format '%r'
_next_choice 'prompt_height'
case r
_begin
case q
_quit
end
end

View File

@ -0,0 +1,8 @@
function fake_lean_left_prompt
for item in fake_lean_{$fake_lean_left_prompt_items}
set -l itemOutput (_$item)
printf '%b' "$itemOutput"
set_color normal
end
end

View File

@ -0,0 +1,30 @@
function fake_lean_right_prompt
set -l splitText (string split '\n' (_fetch_right_prompt_items))
set -l printAtEndedRightPromptHeight (count $splitText)
for thing in $splitText
_print_at_end $thing
end
_cursor_up $printAtEndedRightPromptHeight
end
function _fetch_right_prompt_items
printf '%s' ' '
for item in fake_lean_{$fake_lean_right_prompt_items}
set -l itemOutput (_$item)
printf '%s' "$itemOutput"
set_color normal
end
end
function _print_at_end -a text
set -l startLocation (math $fake_columns -(string length (lean_decolor $text)))
_cursor_right $startLocation
printf '%s' $text
printf '%b' '\v'
printf '%b' '\r'
end

View File

@ -0,0 +1,15 @@
function fake_prompt
if test "$fake_lean_newline" = 'true'
printf '\n'
end
set_color $fake_lean_prompt_connection_color
printf "%.s$fake_lean_prompt_connection_icon" (seq $fake_columns)
set_color $fish_color_normal
printf '\r'
fake_lean_right_prompt
printf '\r'
fake_lean_left_prompt
end

View File

@ -0,0 +1,4 @@
function _fake_lean_cmd_duration
set_color $lean_cmd_duration_color
printf '%s ' '5s'
end

View File

@ -0,0 +1,4 @@
function _fake_lean_git_prompt
set_color $lean_color_green
printf '%s ' 'master'
end

View File

@ -0,0 +1,3 @@
function _fake_lean_newline
printf '%s' '\n'
end

View File

@ -0,0 +1,4 @@
function _fake_lean_prompt_char
set_color $lean_color_green
printf '%s ' ''
end

View File

@ -0,0 +1,14 @@
function _fake_lean_pwd
set_color -o $lean_color_light_blue
printf '%s' '~'
set_color normal
set_color $lean_color_dark_blue
printf '%s' '/'
set_color normal
set_color -o $lean_color_light_blue
printf '%s' 'src'
printf '%s' ' '
end

View File

@ -0,0 +1,4 @@
function _fake_lean_time
set_color $fake_lean_time_color
printf '%s ' (date +$fake_lean_time_format)
end

View File

@ -4,282 +4,46 @@ function lean_configure
return 1 return 1
end end
set -g fishPrompt "$__fish_config_dir/functions/fish_prompt.fish" set -g fake_columns $COLUMNS
set -g fakePrompt "$lean_dir/fake_prompt.fish" if test $fake_columns -gt 100
set -g fake_columns 100
set -g columns $COLUMNS end
if test $columns -gt 100 set -g fake_lines $LINES
set -g columns 100
for fn in $lean_dir/configure/functions/*
source "$fn"
end
for promptItem in $lean_dir/configure/prompt_items/*
source "$promptItem"
end end
set -g lines $LINES
_begin _begin
end end
function _begin function _begin
_setDefaults _set_defaults
_promptTime _next_choice 'show_time'
end end
function _setDefaults function _set_defaults
if test $lines -ge 26 if test $fake_lines -ge 26
set -g new_line true set -g fake_lean_newline true
else else
set -g new_line false set -g fake_lean_newline false
end end
set -g prompt_height 2
set -g fake_lean_left_prompt_items 'pwd' 'git_prompt' 'newline' 'prompt_char'
set -g fake_lean_right_prompt_items 'cmd_duration' 'time'
set -g fake_lean_time_format '' set -g fake_lean_time_format ''
set -g fake_lean_prompt_connection ' ' set -g fake_lean_time_color 5F8787
set -g fake_lean_prompt_connection_icon ' '
set -g fake_lean_prompt_connection_color 6C6C6C set -g fake_lean_prompt_connection_color 6C6C6C
end end
function _promptTime function _next_choice -a nextChoice
_title 'Show current time?' source "$lean_dir/configure/choices/$nextChoice.fish"
$nextChoice
_option 1 'No'
_displayPrompt fake_lean_time_format ''
_option 2 '24-hour format'
_displayPrompt fake_lean_time_format '%T'
_option 3 '12-hour format'
_displayPrompt fake_lean_time_format '%r'
_displayRestartAndQuit
switch (_menu 'Choice' 1/2/3/r/q)
case 1
set -g fake_lean_time_format ''
_promptHeight
case 2
set -g fake_lean_time_format '%T'
_promptHeight
case 3
set -g fake_lean_time_format '%r'
_promptHeight
case r
_begin
case q
_quit
end
end
function _promptHeight
_title 'Prompt Height'
_option 1 'One line'
_displayPrompt prompt_height 1
_option 2 'Two lines'
_displayPrompt prompt_height 2
_displayRestartAndQuit
switch (_menu 'Choice' 1/2/r/q)
case 1
set -g prompt_height 1
_promptSpacing
case 2
set -g prompt_height 2
_promptConnection
case r
_begin
case q
_quit
end
end
function _promptConnection
_title 'Prompt Connection'
_option 1 'Disconnected'
_displayPrompt fake_lean_prompt_connection ' '
_option 2 'Dotted'
_displayPrompt fake_lean_prompt_connection '·'
_option 3 'Solid'
_displayPrompt fake_lean_prompt_connection '─'
_displayRestartAndQuit
switch (_menu 'Choice' 1/2/3/r/q)
case 1
set -g fake_lean_prompt_connection ' '
_promptSpacing
case 2
set -g fake_lean_prompt_connection '·'
_promptConnectionColor
case 3
set -g fake_lean_prompt_connection '─'
_promptConnectionColor
case r
_begin
case q
_quit
end
end
function _promptConnectionColor
_title 'Connection Color'
_option 1 'Lightest'
_displayPrompt fake_lean_prompt_connection_color 808080
_option 2 'Light'
_displayPrompt fake_lean_prompt_connection_color 6C6C6C
_option 3 'Dark'
_displayPrompt fake_lean_prompt_connection_color 585858
_option 4 'Darkest'
_displayPrompt fake_lean_prompt_connection_color 444444
_displayRestartAndQuit
switch (_menu 'Choice' 1/2/3/4/r/q)
case 1
set -g fake_lean_prompt_connection_color 808080
_promptSpacing
case 2
set -g fake_lean_prompt_connection_color 6C6C6C
_promptSpacing
case 3
set -g fake_lean_prompt_connection_color 585858
_promptSpacing
case 4
set -g fake_lean_prompt_connection_color 444444
_promptSpacing
case r
_begin
case q
_quit
end
end
function _promptSpacing
_title 'Prompt Spacing'
_option 1 'Compact'
_displayPrompt new_line true
echo -ne '\r\033[1A'
_displayPrompt new_line false
_option 2 'Sparse'
_displayPrompt new_line true
echo -ne '\r\033[1A'
_displayPrompt new_line true
_displayRestartAndQuit
switch (_menu 'Choice' 1/2/r/q)
case 1
set -g new_line false
_finish
case 2
set -g new_line true
_finish
case r
_begin
case q
_quit
end
end
function _assemblePrompt -a whichPrompt
set -g moduleDir "$lean_dir/prompt_modules/$whichPrompt""_prompt"
if test "$whichPrompt" = 'fish'
set -g promptDir $fishPrompt
else
set -g promptDir $fakePrompt
end
echo -n >$promptDir
_addMod 1_initial
if test "$new_line" = 'true'
_addMod 2_newline
end
_addMod '3_'$prompt_height'Line'
_addMod 4_final
if test $prompt_height -eq 1
_addMod 5_rightPrompt
end
end
function _addMod -a file
cat "$moduleDir/$file.fish" >>$promptDir
printf '\n\n' >>$promptDir
end
function _title -a title
clear
set -l midCols (math $columns/2)
set -l midTitle (math (string length $title)/2)
for i in (seq (math $midCols-$midTitle))
echo -n ' '
end
set_color -o
echo $title
set_color normal
end
function _option -a symbol text
set_color -o
echo "($symbol) $text"
set_color normal
end
function _displayPrompt -a var_name var_value
set -g $var_name $var_value
_assemblePrompt fake
source $promptDir
fake_prompt
printf '\n\n'
end
function _displayRestartAndQuit
echo -e '(r) Restart from the beginning\n'
echo -e '(q) Quit and do nothing\n'
end
function _quit --on-signal INT
functions -e fish_right_prompt
source $fishPrompt
clear
end
function _finish
_title 'Overwrite fish_prompt?'
_option y 'Yes'
printf '\n\n'
_option n 'No'
printf '\n\n'
switch (_menu 'Choice' y/n)
case y
_assemblePrompt fish
set -U lean_prompt_connection_icon $fake_lean_prompt_connection
set -U lean_prompt_connection_color $fake_lean_prompt_connection_color
if test $fake_lean_time_format = ''
if contains 'time' $lean_right_prompt_items
set -e lean_right_prompt_items[(contains -i 'time' $lean_right_prompt_items)]
end
set -e lean_time_format
else
set -a lean_right_prompt_items 'time'
set -U lean_time_format $fake_lean_time_format
end
case n
end
_quit
end end
function _menu -a question options function _menu -a question options
@ -295,4 +59,41 @@ function _menu -a question options
break break
end end
end end
end
function _title -a text
clear
set -l midCols (math -s0 $fake_columns/2)
set -l midTitle (math -s0 (string length $text)/2)
_cursor_right (math $midCols-$midTitle)
set_color -o
echo $text
set_color normal
end
function _option -a symbol text
set_color -o
echo "($symbol) $text"
set_color normal
end
function _display_prompt -a var_name var_value
if test -n "$var_name"
set -g $var_name $var_value
end
fake_prompt
printf '\n\n'
end
function _display_restart_and_quit
printf '(r) Restart from the beginning \n\n'
printf '(q) Quit and do nothing \n\n'
end
function _quit --on-signal INT
source "$__fish_config_dir/functions/fish_prompt.fish"
source "$__fish_config_dir/functions/lean_left_prompt.fish"
source "$__fish_config_dir/functions/lean_right_prompt.fish"
clear
end end

View File

@ -1,4 +0,0 @@
# Created by lean configure
function fake_prompt --description 'Write out the prompt'
set -g last_pipestatus $pipestatus
set -g last_status $status

View File

@ -1,22 +0,0 @@
printf '%.s ' (seq $columns)
set -l rightPrompt ' 5s '(date +$fake_lean_time_format)
set -l rightPromptStartLocation (math $columns-(string length $rightPrompt))
printf '\r\033['$rightPromptStartLocation'C'
set_color $lean_cmd_duration_color
echo -n ' 5s '
set_color $fish_color_normal
set_color $lean_time_color
echo -n (date +$fake_lean_time_format)
set_color $fish_color_normal
echo -ne '\r'
set -l Lblue (set_color -o $lean_color_light_blue)
set -l Dblue (set_color $lean_color_dark_blue)
set -l n (set_color $fish_color_normal)
echo -n $Lblue'~'$n$Dblue'/'$n$Lblue'src '$n
set_color $lean_color_green
echo -n 'master '
set_color $fish_color_normal

View File

@ -1,24 +0,0 @@
set_color $fake_lean_prompt_connection_color
printf "%.s$fake_lean_prompt_connection" (seq $columns)
set_color $fish_color_normal
set -l rightPrompt ' 5s '(date +$fake_lean_time_format)
set -l rightPromptStartLocation (math $columns-(string length $rightPrompt))
printf '\r\033['$rightPromptStartLocation'C'
set_color $lean_cmd_duration_color
echo -n ' 5s '
set_color $fish_color_normal
set_color $lean_time_color
echo -n (date +$fake_lean_time_format)
set_color $fish_color_normal
echo -ne '\r'
set -l Lblue (set_color -o $lean_color_light_blue)
set -l Dblue (set_color $lean_color_dark_blue)
set -l n (set_color $fish_color_normal)
echo -n $Lblue'~'$n$Dblue'/'$n$Lblue'src '$n
set_color $lean_color_green
echo 'master '
set_color $fish_color_normal

View File

@ -1,9 +0,0 @@
# Prompt character
if test $last_status -eq 0
set_color $lean_color_green
else
set_color $fish_color_error
end
echo -n ' '
set_color $fish_color_normal
end

View File

@ -1,5 +0,0 @@
function fish_right_prompt
set_color $lean_cmd_duration_color
echo ' 5s '
set_color $fish_color_normal
end

View File

@ -1,4 +0,0 @@
# Created by lean configure
function fish_prompt --description 'Write out the prompt'
set -g last_pipestatus $pipestatus
set -g last_status $status

View File

@ -1 +0,0 @@
lean_left_prompt

View File

@ -1,11 +0,0 @@
set_color $lean_prompt_connection_color
printf "%.s$lean_prompt_connection_icon" (seq $COLUMNS)
set_color $fish_color_normal
printf '\r'
lean_left_prompt
set -l rightPrompt (lean_right_prompt)
set -l rightPromptStartLocation (math $COLUMNS-(string length (lean_decolor $rightPrompt)))
printf '\r\033['$rightPromptStartLocation'C'
echo $rightPrompt

View File

@ -1,9 +0,0 @@
# Prompt character
if test $last_status -eq 0
set_color $lean_color_green
else
set_color $fish_color_error
end
echo -n ' '
set_color $fish_color_normal
end

View File

@ -1,3 +0,0 @@
function fish_right_prompt
lean_right_prompt
end