From 08ece1640b360d741bd08dc6dc028a42682aa4ed Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Thu, 18 Jan 2024 02:57:55 +0100 Subject: feat(version): add spinner while checking upstream versions It may take quite some time to check a lot of upstream versions. However, we still want to nicely group the results together. To avoid just showing a static status message it makes much more sense to show a dynamic spinner with a summary of the progress. Component: pkgctl version check Component: pkgctl version upgrade Signed-off-by: Levente Polyak --- src/lib/version/check.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++- src/lib/version/upgrade.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/lib/version/check.sh b/src/lib/version/check.sh index ddd400d..fba2d1a 100644 --- a/src/lib/version/check.sh +++ b/src/lib/version/check.sh @@ -8,6 +8,8 @@ DEVTOOLS_INCLUDE_VERSION_CHECK_SH=1 _DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@} # shellcheck source=src/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh +# shellcheck source=src/lib/util/term.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/term.sh source /usr/share/makepkg/util/message.sh @@ -37,11 +39,12 @@ _EOF_ pkgctl_version_check() { local path local pkgbases=() - local path pkgbase upstream_version result + local status_file path pkgbase upstream_version result local up_to_date=() local out_of_date=() local failure=() + local current_item=0 local section_separator='' while (( $# )); do @@ -78,6 +81,10 @@ pkgctl_version_check() { fi fi + # start a terminal spinner as checking versions takes time + status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX) + term_spinner_start "${status_dir}" + for path in "${pkgbases[@]}"; do pushd "${path}" >/dev/null @@ -85,6 +92,16 @@ pkgctl_version_check() { die "No PKGBUILD found for ${path}" fi + # update the current terminal spinner status + (( ++current_item )) + pkgctl_version_check_spinner \ + "${status_dir}" \ + "${#up_to_date[@]}" \ + "${#out_of_date[@]}" \ + "${#failure[@]}" \ + "${current_item}" \ + "${#pkgbases[@]}" + # reset common PKGBUILD variables unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys # shellcheck source=contrib/makepkg/PKGBUILD.proto @@ -120,6 +137,9 @@ pkgctl_version_check() { popd >/dev/null done + # stop the terminal spinner after all checks + term_spinner_stop "${status_dir}" + if (( ${#failure[@]} > 0 )); then printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" section_separator=$'\n' @@ -256,3 +276,30 @@ pkgctl_version_check_summary() { msg_warn " Out-of-date: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1 fi } + +pkgctl_version_check_spinner() { + local status_dir=$1 + local up_to_date_count=$2 + local out_of_date_count=$3 + local failure_count=$4 + local current=$5 + local total=$6 + + local percentage=$(( 100 * current / total )) + local tmp_file="${status_dir}/tmp" + local status_file="${status_dir}/status" + + # print the current summary + pkgctl_version_check_summary \ + "${up_to_date_count}" \ + "${out_of_date_count}" \ + "${failure_count}" > "${tmp_file}" + + # print the progress status + printf "📡 Checking: %s/%s [%s] %%spinner%%" \ + "${BOLD}${current}" "${total}" "${percentage}%${ALL_OFF}" \ + >> "${tmp_file}" + + # swap the status file + mv "${tmp_file}" "${status_file}" +} diff --git a/src/lib/version/upgrade.sh b/src/lib/version/upgrade.sh index 26a5ccb..9f884d0 100644 --- a/src/lib/version/upgrade.sh +++ b/src/lib/version/upgrade.sh @@ -12,6 +12,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/common.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/version/check.sh # shellcheck source=src/lib/util/pkgbuild.sh source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pkgbuild.sh +# shellcheck source=src/lib/util/term.sh +source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/term.sh source /usr/share/makepkg/util/message.sh @@ -41,6 +43,7 @@ pkgctl_version_upgrade() { local path upstream_version result local pkgbases=() local exit_code=0 + local current_item=0 while (( $# )); do case $1 in @@ -76,6 +79,10 @@ pkgctl_version_upgrade() { fi fi + # start a terminal spinner as checking versions takes time + status_dir=$(mktemp --tmpdir="${WORKDIR}" --directory pkgctl-version-check-spinner.XXXXXXXXXX) + term_spinner_start "${status_dir}" + for path in "${pkgbases[@]}"; do pushd "${path}" >/dev/null @@ -83,6 +90,16 @@ pkgctl_version_upgrade() { die "No PKGBUILD found for ${path}" fi + # update the current terminal spinner status + (( ++current_item )) + pkgctl_version_upgrade_spinner \ + "${status_dir}" \ + "${#up_to_date[@]}" \ + "${#out_of_date[@]}" \ + "${#failure[@]}" \ + "${current_item}" \ + "${#pkgbases[@]}" + # reset common PKGBUILD variables unset pkgbase pkgname arch source pkgver pkgrel validpgpkeys # shellcheck source=contrib/makepkg/PKGBUILD.proto @@ -122,6 +139,9 @@ pkgctl_version_upgrade() { popd >/dev/null done + # stop the terminal spinner after all checks + term_spinner_stop "${status_dir}" + if (( ${#failure[@]} > 0 )); then exit_code=1 printf "%sFailure%s\n" "${section_separator}${BOLD}${UNDERLINE}" "${ALL_OFF}" @@ -176,3 +196,30 @@ pkgctl_version_upgrade_summary() { msg_warn " Upgraded: ${BOLD}${out_of_date_count}${ALL_OFF}" 2>&1 fi } + +pkgctl_version_upgrade_spinner() { + local status_dir=$1 + local up_to_date_count=$2 + local out_of_date_count=$3 + local failure_count=$4 + local current=$5 + local total=$6 + + local percentage=$(( 100 * current / total )) + local tmp_file="${status_dir}/tmp" + local status_file="${status_dir}/status" + + # print the current summary + pkgctl_version_upgrade_summary \ + "${up_to_date_count}" \ + "${out_of_date_count}" \ + "${failure_count}" > "${tmp_file}" + + # print the progress status + printf "📡 Upgrading: %s/%s [%s] %%spinner%%" \ + "${BOLD}${current}" "${total}" "${percentage}%${ALL_OFF}" \ + >> "${tmp_file}" + + # swap the status file + mv "${tmp_file}" "${status_file}" +} -- cgit v1.2.3-54-g00ecf