From ff8aceba5b43050d8b4915c1cc1964492feb3e9e Mon Sep 17 00:00:00 2001 From: William Melody Date: Sun, 6 Feb 2022 15:14:50 -0800 Subject: [PATCH] Hide `_spinner --no-color` output, waiting until `` exits. --- nb | 24 ++++++++++++++---------- test/helpers-spinner.bats | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 test/helpers-spinner.bats diff --git a/nb b/nb index 842f18ebb..853323640 100755 --- a/nb +++ b/nb @@ -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() diff --git a/test/helpers-spinner.bats b/test/helpers-spinner.bats new file mode 100644 index 000000000..f0ee1fde3 --- /dev/null +++ b/test/helpers-spinner.bats @@ -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}" ]] +}