diff options
| author | Ryan Schanzenbacher <ryan@rschanz.org> | 2024-04-05 11:57:45 -0400 |
|---|---|---|
| committer | Ryan Schanzenbacher <ryan@rschanz.org> | 2024-04-05 11:57:45 -0400 |
| commit | b88d77fb2d0d5028a6f5670695dee6bec129501f (patch) | |
| tree | 2536b0461d297e647cf07157641c9b1223339adf /home-config/fish/functions/_tide_sub_configure.fish | |
| parent | 776a7ca55d2d2c3f396de91db1c6c3c5065012cd (diff) | |
ahhh sloppy fish, still needs fixing, esp with the vars
Diffstat (limited to 'home-config/fish/functions/_tide_sub_configure.fish')
| -rw-r--r-- | home-config/fish/functions/_tide_sub_configure.fish | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/home-config/fish/functions/_tide_sub_configure.fish b/home-config/fish/functions/_tide_sub_configure.fish new file mode 100644 index 0000000..22faf3a --- /dev/null +++ b/home-config/fish/functions/_tide_sub_configure.fish | |||
| @@ -0,0 +1,156 @@ | |||
| 1 | set -g _tide_color_dark_blue 0087AF | ||
| 2 | set -g _tide_color_dark_green 5FAF00 | ||
| 3 | set -g _tide_color_gold D7AF00 | ||
| 4 | set -g _tide_color_green 5FD700 | ||
| 5 | set -g _tide_color_light_blue 00AFFF | ||
| 6 | |||
| 7 | # Create an empty fake function for each item | ||
| 8 | for func in _fake(functions --all | string match --entire _tide_item) | ||
| 9 | function $func | ||
| 10 | end | ||
| 11 | end | ||
| 12 | |||
| 13 | for file in (status dirname)/tide/configure/{choices, functions}/**.fish | ||
| 14 | source $file | ||
| 15 | end | ||
| 16 | |||
| 17 | function _tide_sub_configure | ||
| 18 | set -l choices (path basename (status dirname)/tide/configure/choices/**.fish | path change-extension '') | ||
| 19 | argparse auto $choices= -- $argv | ||
| 20 | |||
| 21 | for var in (set -l --names | string match -e _flag) | ||
| 22 | set -x $var $$var | ||
| 23 | end | ||
| 24 | |||
| 25 | if set -q _flag_auto | ||
| 26 | set -fx _flag_finish 'Overwrite your current tide config' | ||
| 27 | else if test $COLUMNS -lt 55 -o $LINES -lt 21 | ||
| 28 | echo 'Terminal size too small; must be at least 55 x 21' | ||
| 29 | return 1 | ||
| 30 | end | ||
| 31 | |||
| 32 | _tide_detect_os | read -g --line os_branding_icon os_branding_color os_branding_bg_color | ||
| 33 | |||
| 34 | set -g fake_columns $COLUMNS | ||
| 35 | test $fake_columns -gt 90 && set fake_columns 90 | ||
| 36 | set -g fake_lines $LINES | ||
| 37 | |||
| 38 | set -g _tide_selected_option | ||
| 39 | _next_choice all/style | ||
| 40 | end | ||
| 41 | |||
| 42 | function _next_choice -a nextChoice | ||
| 43 | set -q _tide_selected_option || return 0 | ||
| 44 | set -l cmd (string split '/' $nextChoice)[2] | ||
| 45 | $cmd | ||
| 46 | end | ||
| 47 | |||
| 48 | function _tide_title -a text | ||
| 49 | set -q _flag_auto && return | ||
| 50 | |||
| 51 | command -q clear && clear | ||
| 52 | set_color -o | ||
| 53 | string pad --width (math --scale=0 "$fake_columns/2" + (string length $text)/2) $text | ||
| 54 | set_color normal | ||
| 55 | |||
| 56 | set -g _tide_configure_first_option_after_title | ||
| 57 | end | ||
| 58 | |||
| 59 | function _tide_option -a symbol text | ||
| 60 | set -ga _tide_symbol_list $symbol | ||
| 61 | set -ga _tide_option_list $text | ||
| 62 | |||
| 63 | if not set -q _flag_auto | ||
| 64 | set -g _tide_configure_first_prompt_after_option | ||
| 65 | |||
| 66 | set_color -o | ||
| 67 | set -e _tide_configure_first_option_after_title || echo | ||
| 68 | echo "($symbol) $text" | ||
| 69 | set_color normal | ||
| 70 | end | ||
| 71 | end | ||
| 72 | |||
| 73 | function _tide_menu -a func | ||
| 74 | if set -q _flag_auto | ||
| 75 | set -l flag_var_name _flag_$func | ||
| 76 | set -g _tide_selected_option $$flag_var_name | ||
| 77 | |||
| 78 | if test -z "$_tide_selected_option" | ||
| 79 | echo "Missing input for choice '$func'" | ||
| 80 | _tide_exit_configure | ||
| 81 | else if not contains $_tide_selected_option $_tide_option_list | ||
| 82 | echo "Invalid input '$_tide_selected_option' for choice '$func'" | ||
| 83 | _tide_exit_configure | ||
| 84 | else | ||
| 85 | set -e _tide_symbol_list | ||
| 86 | set -e _tide_option_list | ||
| 87 | end | ||
| 88 | return | ||
| 89 | end | ||
| 90 | |||
| 91 | argparse no-restart -- $argv # Add no-restart option for first menu | ||
| 92 | |||
| 93 | echo | ||
| 94 | if not set -q _flag_no_restart | ||
| 95 | set -f r r | ||
| 96 | echo '(r) Restart from the beginning' | ||
| 97 | end | ||
| 98 | echo '(q) Quit and do nothing'\n | ||
| 99 | |||
| 100 | while read --nchars 1 --prompt-str \ | ||
| 101 | "$(set_color -o)Choice [$(string join '/' $_tide_symbol_list $r q)] $(set_color normal)" input | ||
| 102 | switch $input | ||
| 103 | case r | ||
| 104 | set -q _flag_no_restart && continue | ||
| 105 | set -e _tide_symbol_list | ||
| 106 | set -e _tide_option_list | ||
| 107 | _next_choice all/style | ||
| 108 | break | ||
| 109 | case q | ||
| 110 | _tide_exit_configure | ||
| 111 | set -e _tide_symbol_list | ||
| 112 | set -e _tide_option_list | ||
| 113 | command -q clear && clear | ||
| 114 | break | ||
| 115 | case $_tide_symbol_list | ||
| 116 | set -g _tide_selected_option $_tide_option_list[(contains -i $input $_tide_symbol_list)] | ||
| 117 | test "$func" != finish && | ||
| 118 | set -a _tide_configure_current_options --$func=(string escape $_tide_selected_option) | ||
| 119 | set -e _tide_symbol_list | ||
| 120 | set -e _tide_option_list | ||
| 121 | break | ||
| 122 | end | ||
| 123 | end | ||
| 124 | end | ||
| 125 | |||
| 126 | function _tide_display_prompt | ||
| 127 | set -q _flag_auto && return | ||
| 128 | |||
| 129 | _fake_tide_cache_variables | ||
| 130 | set -l prompt (_fake_tide_prompt) | ||
| 131 | |||
| 132 | set -l bottom_left_prompt_string_length (string length --visible $prompt[-1]) | ||
| 133 | set -l right_prompt_string (string pad --width (math $fake_columns-$bottom_left_prompt_string_length) $prompt[1]) | ||
| 134 | set -l prompt[-1] "$prompt[-1]$right_prompt_string" | ||
| 135 | |||
| 136 | if set -q _configure_transient | ||
| 137 | if contains newline $fake_tide_left_prompt_items | ||
| 138 | string unescape $prompt[3..] | ||
| 139 | else | ||
| 140 | _fake_tide_item_character | ||
| 141 | echo | ||
| 142 | end | ||
| 143 | else | ||
| 144 | if not set -q _tide_configure_first_prompt_after_option | ||
| 145 | test "$fake_tide_prompt_add_newline_before" = true && echo | ||
| 146 | end | ||
| 147 | string unescape $prompt[2..] | ||
| 148 | end | ||
| 149 | |||
| 150 | set -e _tide_configure_first_prompt_after_option | ||
| 151 | set_color normal | ||
| 152 | end | ||
| 153 | |||
| 154 | function _tide_exit_configure | ||
| 155 | set -e _tide_selected_option # Skip through all switch and _next_choice | ||
| 156 | end | ||
