tide/functions/lean_wizard.fish

262 lines
5.5 KiB
Fish
Raw Normal View History

function lean_wizard
if test $COLUMNS -lt 55 || test $LINES -lt 21
echo "Terminal size too small; must be at least 55 x 21"
return 1
end
set -g fishPrompt "$__fish_config_dir/functions/fish_prompt.fish"
2020-04-28 01:10:59 +03:00
set -g fakePrompt "$__fish_config_dir/lean_theme/fake_prompt.fish"
2020-04-28 01:37:08 +03:00
set -g columns $COLUMNS
2020-04-28 01:37:08 +03:00
if test $columns -gt 100
set -g columns 100
end
set -g lines $LINES
_begin
end
function _begin
clear
_setDefaults
_promptHeight
end
function _setDefaults
if test $lines -ge 26
set -g newline true
else
set -g newline false
end
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection " "
set -g fake_lean_prompt_connection_color 6C6C6C
end
function _promptHeight
_title "Prompt Height"
2020-04-21 21:52:24 +03:00
_option 1 "One line"
_displayPrompt prompt_height 1
2020-04-21 21:52:24 +03:00
_option 2 "Two lines"
_displayPrompt prompt_height 2
_displayRestartAndQuit
switch (_menu "Choice" 1/2/r/q)
case 1
set -g prompt_height 1
2020-04-21 21:52:24 +03:00
_promptSpacing
case 2
set -g prompt_height 2
_promptConnection
case r
_begin
case q
_quit
end
end
function _promptConnection
clear
_title "Prompt Connection"
2020-04-21 21:52:24 +03:00
_option 1 "Disconnected"
2020-04-21 06:35:56 +03:00
_displayPrompt fake_lean_prompt_connection " "
2020-04-21 21:52:24 +03:00
_option 2 "Dotted"
2020-04-21 06:35:56 +03:00
_displayPrompt fake_lean_prompt_connection "·"
2020-04-21 21:52:24 +03:00
_option 3 "Solid"
2020-04-21 06:35:56 +03:00
_displayPrompt fake_lean_prompt_connection "─"
_displayRestartAndQuit
switch (_menu "Choice" 1/2/3/r/q)
case 1
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection " "
_promptSpacing
case 2
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection "·"
_promptConnectionColor
case 3
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection "─"
_promptConnectionColor
case r
_begin
case q
_quit
end
end
function _promptConnectionColor
clear
_title "Connection Color"
2020-04-21 21:52:24 +03:00
_option 1 "Lightest"
2020-04-21 06:35:56 +03:00
_displayPrompt fake_lean_prompt_connection_color 808080
2020-04-21 21:52:24 +03:00
_option 2 "Light"
2020-04-21 06:35:56 +03:00
_displayPrompt fake_lean_prompt_connection_color 6C6C6C
2020-04-21 21:52:24 +03:00
_option 3 "Dark"
2020-04-21 06:35:56 +03:00
_displayPrompt fake_lean_prompt_connection_color 585858
2020-04-21 21:52:24 +03:00
_option 4 "Darkest"
2020-04-21 06:35:56 +03:00
_displayPrompt fake_lean_prompt_connection_color 444444
_displayRestartAndQuit
switch (_menu "Choice" 1/2/3/4/r/q)
case 1
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection_color 808080
_promptSpacing
case 2
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection_color 6C6C6C
_promptSpacing
case 3
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection_color 585858
_promptSpacing
case 4
2020-04-21 06:35:56 +03:00
set -g fake_lean_prompt_connection_color 444444
_promptSpacing
case r
_begin
case q
_quit
end
end
function _promptSpacing
clear
_title "Prompt Spacing"
2020-04-21 21:52:24 +03:00
_option 1 "Compact"
_displayPrompt newline true
2020-04-21 21:52:24 +03:00
echo -ne "\r\033[1A"
_displayPrompt newline false
2020-04-21 21:52:24 +03:00
_option 2 "Sparse"
_displayPrompt newline true
2020-04-21 21:52:24 +03:00
echo -ne "\r\033[1A"
_displayPrompt newline true
_displayRestartAndQuit
switch (_menu "Choice" 1/2/r/q)
case 1
set -g newline false
_finish
case 2
set -g newline true
_finish
case r
_begin
case q
_quit
end
end
function _assemblePrompt -a whichPrompt
set -g moduleDir "$__fish_config_dir/lean_theme/prompt_modules/$whichPrompt""_prompt"
2020-04-21 06:35:56 +03:00
2020-04-28 01:10:59 +03:00
if test "$whichPrompt" = "fish"
set -g promptDir $fishPrompt
2020-04-21 06:35:56 +03:00
else
2020-04-28 01:10:59 +03:00
set -g promptDir $fakePrompt
2020-04-21 06:35:56 +03:00
end
echo -n >$promptDir
_addMod 1_initial
2020-04-28 01:10:59 +03:00
if test "$newline" = "true"
_addMod 2_newline
end
_addMod "3_"$prompt_height"Line"
_addMod 4_final
2020-04-21 21:52:24 +03:00
if test $prompt_height -eq 1
_addMod 5_rightPrompt
else
_addMod 5_rPromptNoColor
end
end
function _addMod -a file
2020-04-21 21:52:24 +03:00
cat "$moduleDir/$file.fish" >>$promptDir
2020-04-21 06:35:56 +03:00
printf "\n\n" >>$promptDir
end
function _title -a title
set -l midCols (math $columns/2)
set -l midTitle (math (string length $title)/2)
for i in (seq (math $midCols-$midTitle))
echo -n " "
end
2020-04-21 21:52:24 +03:00
set_color -o
echo $title
2020-04-21 21:52:24 +03:00
set_color normal
end
function _option -a symbol text
2020-04-21 21:52:24 +03:00
set_color -o
echo "($symbol) $text"
2020-04-21 21:52:24 +03:00
set_color normal
end
function _displayPrompt -a var_name var_value
set -g $var_name $var_value
2020-04-21 06:35:56 +03:00
_assemblePrompt fake
source $promptDir
fake_prompt
2020-04-22 03:40:49 +03:00
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
2020-04-22 03:40:49 +03:00
functions -e fish_right_prompt
source $fishPrompt
clear
end
function _finish
clear
_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 $fake_lean_prompt_connection
set -U lean_prompt_connection_color $fake_lean_prompt_connection_color
case n
end
2020-04-21 06:35:56 +03:00
_quit
end
function _menu -a question options
set -l optionList (string split "/" $options)
2020-04-22 06:25:40 +03:00
set -l bold (set_color -o)
set -l norm (set_color normal)
while true
2020-04-22 06:25:40 +03:00
read -P $bold"$question [$options] "$norm input
if contains $input $optionList
echo $input
break
end
end
end