feat: add compose-style grouped progress
This commit is contained in:
1 parent
475434042c
commit
ae5a980cac
1 file changed
+23
-5
@@ -290,20 +290,26 @@ run_group() {
|
||||
local action="$2"
|
||||
local group_name="${GROUP_NAMES[group_index]}"
|
||||
local limit="${GROUP_LIMITS[group_index]}"
|
||||
local stack pid finished_pid status result result_color success_result details
|
||||
local next=0 running=0 completed=0 failed=0
|
||||
local stack pid finished_pid status result result_color marker success_result details
|
||||
local next=0 running=0 completed=0 failed=0 stack_width=0 interactive=0
|
||||
local success_color="" failure_color="" color_reset=""
|
||||
local -a stacks=()
|
||||
local -A pid_stacks=()
|
||||
|
||||
if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then
|
||||
if [[ -t 1 ]]; then
|
||||
interactive=1
|
||||
if [[ -z "${NO_COLOR:-}" ]]; then
|
||||
success_color=$'\033[32m'
|
||||
failure_color=$'\033[31m'
|
||||
color_reset=$'\033[0m'
|
||||
fi
|
||||
fi
|
||||
|
||||
read -r -a stacks <<<"${GROUP_STACKS[group_index]}"
|
||||
((${#stacks[@]} > 0)) || return 0
|
||||
for stack in "${stacks[@]}"; do
|
||||
((${#stack} > stack_width)) && stack_width="${#stack}"
|
||||
done
|
||||
|
||||
if ((limit == 0 || limit > ${#stacks[@]})); then
|
||||
limit="${#stacks[@]}"
|
||||
@@ -318,7 +324,11 @@ run_group() {
|
||||
fi
|
||||
|
||||
echo
|
||||
if ((interactive)); then
|
||||
printf '[+] %s: %s 0/%d\n' "$group_name" "$action" "${#stacks[@]}"
|
||||
else
|
||||
echo "==> Group $group_name: $action ($details)"
|
||||
fi
|
||||
|
||||
case "$action" in
|
||||
up | start) success_result="Started" ;;
|
||||
@@ -348,10 +358,12 @@ run_group() {
|
||||
((running -= 1))
|
||||
|
||||
if ((status == 0)); then
|
||||
marker="✔"
|
||||
result="$success_result"
|
||||
result_color="$success_color"
|
||||
((RUN_SUCCESS += 1))
|
||||
else
|
||||
marker="✘"
|
||||
result="Failed"
|
||||
result_color="$failure_color"
|
||||
((RUN_FAILED += 1))
|
||||
@@ -360,8 +372,14 @@ run_group() {
|
||||
fi
|
||||
|
||||
((completed += 1))
|
||||
printf '[%d/%d] %s: %s%s%s\n' \
|
||||
"$completed" "${#stacks[@]}" "$stack" \
|
||||
if ((interactive)); then
|
||||
printf '\033[%dA\r\033[2K[+] %s: %s %d/%d\n' \
|
||||
"$completed" "$group_name" "$action" "$completed" "${#stacks[@]}"
|
||||
((completed > 1)) && printf '\033[%dB\r' "$((completed - 1))"
|
||||
fi
|
||||
|
||||
printf ' %s%s%s Stack %-*s %s%s%s\n' \
|
||||
"$result_color" "$marker" "$color_reset" "$stack_width" "$stack" \
|
||||
"$result_color" "$result" "$color_reset"
|
||||
done
|
||||
|
||||
|
||||
Reference in new issue
Block a user