Skip to content

Commit

Permalink
Hide _spinner --no-color output, waiting until <pid> exits.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwmx committed Feb 6, 2022
1 parent 14b53c3 commit ff8aceb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
24 changes: 14 additions & 10 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -2955,23 +2955,27 @@ _spinner() {
do
local _temp="${_spin_string#?}"

printf " %s%s[%s%c%s]%s" \
"${_TPUT_SGR0}" \
"${_TPUT_SETAF_8}" \
"${_TPUT_COLOR_PRIMARY}" \
"${_spin_string}" \
"${_TPUT_SETAF_8}" \
"${_TPUT_SGR0}"
if ((_COLOR_ENABLED))
then
printf " %s%s[%s%c%s]%s" \
"${_TPUT_SGR0}" \
"${_TPUT_SETAF_8}" \
"${_TPUT_COLOR_PRIMARY}" \
"${_spin_string}" \
"${_TPUT_SETAF_8}" \
"${_TPUT_SGR0}"
fi

sleep ${_delay}

_spin_string="${_temp}${_spin_string%"${_temp}"}"

printf "\b\b\b\b\b\b\b\b"

((_COLOR_ENABLED)) && printf "\b\b\b\b\b\b\b\b"
done

printf " \b\b\b\b\b\b\b\b"
((_COLOR_ENABLED)) && printf " \b\b\b\b\b\b\b\b"

return 0
}

# _string_is_email()
Expand Down
35 changes: 35 additions & 0 deletions test/helpers-spinner.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bats

load test_helper

@test "'_spinner()' displays color spinner for the duration of the specified process." {
{
(sleep 3) &
}

run "${_NB}" helpers spinner $!

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ "${#lines[@]}" -eq 1 ]]
[[ ! "${lines[0]}" =~ \[\|\] ]]
[[ "${lines[0]}" =~ \[.*\|.*\] ]]
[[ "${lines[0]}" =~ \
.*\[.*\-.*\].*\ .*\[.*\/.*\].*\ .*\[.*\|.*\].* ]]
}

@test "'_spinner() --no-color' displays nothing and waits for the duration of the specified process." {
{
(sleep 3) &
}

run "${_NB}" helpers spinner $! --no-color

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

[[ "${status}" -eq 0 ]]
[[ -z "${output}" ]]
}

0 comments on commit ff8aceb

Please sign in to comment.