feat: add compose-style grouped progress

This commit is contained in:
lingkai5wu committed 2026-10-10 17:04:51 +08:00
1 parent 475434042c
commit ae5a980cac
1 file changed
+23 -5
+23 -5
View File
@@ -290,20 +290,26 @@ run_group() {
local action="$2" local action="$2"
local group_name="${GROUP_NAMES[group_index]}" local group_name="${GROUP_NAMES[group_index]}"
local limit="${GROUP_LIMITS[group_index]}" local limit="${GROUP_LIMITS[group_index]}"
local stack pid finished_pid status result result_color success_result details local stack pid finished_pid status result result_color marker success_result details
local next=0 running=0 completed=0 failed=0 local next=0 running=0 completed=0 failed=0 stack_width=0 interactive=0
local success_color="" failure_color="" color_reset="" local success_color="" failure_color="" color_reset=""
local -a stacks=() local -a stacks=()
local -A pid_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' success_color=$'\033[32m'
failure_color=$'\033[31m' failure_color=$'\033[31m'
color_reset=$'\033[0m' color_reset=$'\033[0m'
fi fi
fi
read -r -a stacks <<<"${GROUP_STACKS[group_index]}" read -r -a stacks <<<"${GROUP_STACKS[group_index]}"
((${#stacks[@]} > 0)) || return 0 ((${#stacks[@]} > 0)) || return 0
for stack in "${stacks[@]}"; do
((${#stack} > stack_width)) && stack_width="${#stack}"
done
if ((limit == 0 || limit > ${#stacks[@]})); then if ((limit == 0 || limit > ${#stacks[@]})); then
limit="${#stacks[@]}" limit="${#stacks[@]}"
@@ -318,7 +324,11 @@ run_group() {
fi fi
echo echo
if ((interactive)); then
printf '[+] %s: %s 0/%d\n' "$group_name" "$action" "${#stacks[@]}"
else
echo "==> Group $group_name: $action ($details)" echo "==> Group $group_name: $action ($details)"
fi
case "$action" in case "$action" in
up | start) success_result="Started" ;; up | start) success_result="Started" ;;
@@ -348,10 +358,12 @@ run_group() {
((running -= 1)) ((running -= 1))
if ((status == 0)); then if ((status == 0)); then
marker="✔"
result="$success_result" result="$success_result"
result_color="$success_color" result_color="$success_color"
((RUN_SUCCESS += 1)) ((RUN_SUCCESS += 1))
else else
marker="✘"
result="Failed" result="Failed"
result_color="$failure_color" result_color="$failure_color"
((RUN_FAILED += 1)) ((RUN_FAILED += 1))
@@ -360,8 +372,14 @@ run_group() {
fi fi
((completed += 1)) ((completed += 1))
printf '[%d/%d] %s: %s%s%s\n' \ if ((interactive)); then
"$completed" "${#stacks[@]}" "$stack" \ 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" "$result_color" "$result" "$color_reset"
done done