From be227de5a7fba3540dc9aa89c59b76958c19b4ee Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Tue, 21 Apr 2020 20:06:05 -0700 Subject: [PATCH] Rm lean_user_ask in favor of situation specific menus --- functions/lean_uninstall.fish | 17 ++++++++++++++++- functions/lean_user_ask.fish | 36 ----------------------------------- functions/lean_wizard.fish | 21 ++++++++++++++++---- install.fish | 23 +++++++++++++++++++++- 4 files changed, 55 insertions(+), 42 deletions(-) delete mode 100644 functions/lean_user_ask.fish diff --git a/functions/lean_uninstall.fish b/functions/lean_uninstall.fish index c81d167..8b439fb 100644 --- a/functions/lean_uninstall.fish +++ b/functions/lean_uninstall.fish @@ -1,5 +1,5 @@ function lean_uninstall - if lean_user_ask "Unininstall lean theme?" y/N + if _user_confirm_defaultNo "Unininstall lean theme?" echo "Uninstalling lean theme..." # ------------------Remove Files------------------ @@ -38,4 +38,19 @@ function lean_uninstall else echo "Aborted uninstall." end +end + +function _user_confirm_defaultNo --argument-names question + while true + read -P "$question [y/N] " input + + switch $input + case y Y yes Yes + return 0 + case n N no No + return 1 + case '' + return 1 + end + end end \ No newline at end of file diff --git a/functions/lean_user_ask.fish b/functions/lean_user_ask.fish deleted file mode 100644 index 6beea42..0000000 --- a/functions/lean_user_ask.fish +++ /dev/null @@ -1,36 +0,0 @@ -function lean_user_ask --argument-names question options - set -l optionList (string split "/" $options) - - for option in $optionList - set -g upperOption (string upper $option) - - if contains $upperOption $optionList - set -g default (_indexMinusOne $upperOption $optionList) - end - end - - while true - read -P "$question [$options] " input - - set -l splitInput (string split -m1 '' $input) - set -l lowerInput (string join '' (string lower $splitInput[1]) $splitInput[2]) - set -l upperInput (string join '' (string upper $splitInput[1]) $splitInput[2]) - - if contains $lowerInput $optionList - echo $lowerInput - return (_indexMinusOne $lowerInput $optionList) - end - if contains $upperInput $optionList - echo $upperInput - return (_indexMinusOne $upperInput $optionList) - end - if test -z $input && set -q default - echo $upperOption - return $default - end - end -end - -function _indexMinusOne --argument-names item - echo (math (contains -i $item $argv[2..-1])-1) -end \ No newline at end of file diff --git a/functions/lean_wizard.fish b/functions/lean_wizard.fish index fca8f83..afe3a91 100644 --- a/functions/lean_wizard.fish +++ b/functions/lean_wizard.fish @@ -35,7 +35,7 @@ function _promptHeight _displayRestartAndQuit - switch (lean_user_ask "Choice" 1/2/r/q) + switch (_menu "Choice" 1/2/r/q) case 1 set -g prompt_height 1 _promptSpacing @@ -64,7 +64,7 @@ function _promptConnection _displayRestartAndQuit - switch (lean_user_ask "Choice" 1/2/3/r/q) + switch (_menu "Choice" 1/2/3/r/q) case 1 set -g fake_lean_prompt_connection " " _promptSpacing @@ -99,7 +99,7 @@ function _promptConnectionColor _displayRestartAndQuit - switch (lean_user_ask "Choice" 1/2/3/4/r/q) + switch (_menu "Choice" 1/2/3/4/r/q) case 1 set -g fake_lean_prompt_connection_color 808080 _promptSpacing @@ -135,7 +135,7 @@ function _promptSpacing _displayRestartAndQuit - switch (lean_user_ask "Choice" 1/2/r/q) + switch (_menu "Choice" 1/2/r/q) case 1 set -g newline false _finish @@ -221,4 +221,17 @@ function _finish set -U lean_prompt_connection $fake_lean_prompt_connection set -U lean_prompt_connection_color $fake_lean_prompt_connection_color _quit +end + +function _menu --argument-names question options + set -l optionList (string split "/" $options) + + while true + read -P "$question [$options] " input + + if contains $input $optionList + echo $input + break + end + end end \ No newline at end of file diff --git a/install.fish b/install.fish index 90adf68..038325b 100644 --- a/install.fish +++ b/install.fish @@ -55,6 +55,27 @@ function lean_install source "$__fish_config_dir/functions/fish_prompt.fish" set_color $lean_color_green - echo "Lean theme installed! Run lean_wizard to configure your prompt." + echo "Lean theme installed!" set_color $fish_color_normal + + if _user_confirm_defaultYes "Configure prompt?" + lean_wizard + else + echo -e "\n""Run lean_wizard to configure your prompt." + end +end + +function _user_confirm_defaultYes --argument-names question + while true + read -P "$question [Y/n] " input + + switch $input + case y Y yes Yes + return 0 + case n N no No + return 1 + case '' + return 0 + end + end end \ No newline at end of file