Skip to content

Commit 2d48710

Browse files
committed
refactor: progress.sh extract progress::enabled()
1 parent f10c444 commit 2d48710

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/progress.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env bash
22

3+
function progress::enabled() {
4+
env::is_progress_bar_enabled && ! parallel::is_enabled
5+
}
6+
37
function progress::init() {
48
export PROGRESS_TOTAL=$1
59
# Track the last rendered progress state so the bar can be redrawn
610
export PROGRESS_CURRENT=0
711

8-
if parallel::is_enabled || [[ ! -t 1 ]] || ! env::is_progress_bar_enabled; then
9-
_PROGRESS_ENABLED=false
10-
else
11-
_PROGRESS_ENABLED=true
12+
if progress::enabled ; then
1213
progress::render 0 "$PROGRESS_TOTAL"
1314
fi
1415
}
@@ -19,7 +20,7 @@ function progress::render() {
1920

2021
PROGRESS_CURRENT=$current
2122

22-
if [[ "$_PROGRESS_ENABLED" != true ]]; then
23+
if ! progress::enabled ; then
2324
return
2425
fi
2526

@@ -60,7 +61,7 @@ function progress::render() {
6061
}
6162

6263
function progress::finish() {
63-
if [[ "$_PROGRESS_ENABLED" != true ]]; then
64+
if ! progress::enabled ; then
6465
return
6566
fi
6667

@@ -76,7 +77,7 @@ function progress::finish() {
7677

7778
# Re-render the last progress bar if progress display is enabled
7879
function progress::refresh() {
79-
if [[ "$_PROGRESS_ENABLED" == true ]]; then
80+
if progress::enabled ; then
8081
progress::render "${PROGRESS_CURRENT:-}" "${PROGRESS_TOTAL:-}"
8182
fi
8283
}

0 commit comments

Comments
 (0)