From 96a1272506f8ca247f8a07acacacd0e49492f7df Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sat, 4 May 2024 10:39:10 +0100 Subject: [PATCH] Remove zcurses build-dir selector --- build/build.plugin.zsh | 84 +++++------------------------------------- 1 file changed, 10 insertions(+), 74 deletions(-) diff --git a/build/build.plugin.zsh b/build/build.plugin.zsh index 456a1e7..bcad7aa 100644 --- a/build/build.plugin.zsh +++ b/build/build.plugin.zsh @@ -87,80 +87,16 @@ EOF elif [[ ${#local_build_dirs} -eq 1 ]]; then local_build_dir=${local_build_dirs[1]} elif [[ ${#local_build_dirs} -gt 1 ]]; then - if command -v fzf &> /dev/null; then - # Use fzf to select a build directory - local max=$(( $( tput lines ) / 2 )) - local best=$(( ${#local_build_dirs} + 4 )) - local_build_dir=$( - printf '%s\n' "${local_build_dirs[@]}" | - fzf --layout=reverse --tac --info=hidden --border=rounded \ - --cycle --height=$(( $best < $max ? $best : $max )) - ) - if [[ $? -ne 0 ]]; then - return 1 - fi - else - # Fallback to zcurses selector when fzf is not available - zmodload zsh/curses && { - # Get the size of the terminal - local size=`stty size` - integer height=${size% *} - integer width=${size#* } - - # Create the window and hide the cursor - zcurses init - zcurses addwin build-dir $height $width 0 0 - - # Hide the cursor for zcurses, trap SIGINT to ensure cleanup in - # always-list occurs below - tput civis; trap 'return 130' INT - - # Enter display loop - local key keypad - while (( 1 )); do - zcurses clear build-dir - - # Add the prompt text - zcurses move build-dir 1 1 - zcurses string build-dir 'Select a build directory:' - - # Add the selections text - for (( i = 0; i < ${#local_build_dirs}; i++ )); do - integer line=$i+3 - zcurses move build-dir $line 1 - [[ $index -eq $i ]] && - zcurses string build-dir "* " || - zcurses string build-dir " " - zcurses string build-dir ${local_build_dirs[$i+1]} - done - - # Display the text the and wait for input - zcurses refresh build-dir - zcurses input build-dir key keypad - - # Handle user input - case $key in - (UP|k|$'\C-P') - [[ $index -gt 0 ]] && index=$index-1 ;; - (DOWN|j|$'\C-N') - [[ $index -lt ${#local_build_dirs}-1 ]] && index=$index+1 ;; - (ENTER|$'\n') - break ;; - esac - done - } always { - # Restore the cursor and cleanup zcurses - tput cvvis; tput cnorm - zcurses delwin build-dir - zcurses end - } - - # On success setup the build directory for use - if [[ $? -eq 0 ]]; then - # Set the build directory from selection if empty - [[ -z $local_build_dir ]] && \ - local_build_dir=${local_build_dirs[$index+1]} - fi + # Use fzf to select a build directory + local max=$(( $( tput lines ) / 2 )) + local best=$(( ${#local_build_dirs} + 4 )) + local_build_dir=$( + printf '%s\n' "${local_build_dirs[@]}" | + fzf --layout=reverse --tac --info=hidden --border=rounded \ + --cycle --height=$(( $best < $max ? $best : $max )) + ) + if [[ $? -ne 0 ]]; then + return 1 fi fi fi