Skip to content

refactor: extract spinner logic into function #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions faff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ FAFF_TIMEOUT=${FAFF_TIMEOUT:-180}
# Spinner characters for progress indication
SPINNER_CHARS=( "⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏" )

# Calculate next spinner index
function next_spinner_index() {
local current_index=$1
echo $(((current_index + 1) % ${#SPINNER_CHARS[@]}))
}

# Output error message to stderr
function error_exit() {
echo "Error: $1" >&2
Expand Down Expand Up @@ -62,7 +68,7 @@ function show_spinner() {
while kill -0 $pid 2>/dev/null; do
local spin_char=${SPINNER_CHARS[$i]}
printf "\r%s %s" "$spin_char" "$message" >&2
i=$(((i + 1) % ${#SPINNER_CHARS[@]}))
i=$(next_spinner_index $i)
sleep 0.1
done
printf "\r%*s\r" "50" "" >&2 # Clear the spinner line completely
Expand Down Expand Up @@ -323,13 +329,13 @@ function check_model() {
total_formatted=$(format_download_size "$total")

spin_char=${SPINNER_CHARS[$i]}
i=$(((i + 1) % ${#SPINNER_CHARS[@]}))
i=$(next_spinner_index $i)

echo -ne "\\r$spin_char Downloading: $percent% ($completed_formatted/$total_formatted) " >&2
else
# Show spinner even without detailed progress
spin_char=${SPINNER_CHARS[$i]}
i=$(((i + 1) % ${#SPINNER_CHARS[@]}))
i=$(next_spinner_index $i)

status=$(echo "$line" | jq -r '.status // "downloading"')
echo -ne "\\r$spin_char $status... " >&2
Expand Down