Skip to content

fix: properly clear finished bars when CleanOnFinish is enabled in pool - #252

Closed
AdamMagued wants to merge 1 commit into
cheggaaa:masterfrom
AdamMagued:fix-pool-clean-on-finish
Closed

AdamMagued wants to merge 1 commit into
cheggaaa:masterfrom
AdamMagued:fix-pool-clean-on-finish

Conversation

@AdamMagued

Copy link
Copy Markdown

When progress bars within a Pool have CleanOnFinish enabled, finishing individual bars or stopping the pool leaves trailing bar lines during pool redraw cycles because Pool.print does not account for CleanOnFinish and unconditionally renders all bars.

Changes

  • In Pool.print:
    • Identify and filter out completed bars that have CleanOnFinish enabled.
    • Overwrite lines left by cleared bars with spaces when the active bar count decreases.
    • Reposition the cursor back to the bottom of the remaining active bars.
    • Prune finished CleanOnFinish bars from p.bars to avoid unbounded slice growth and ensure terminal height truncation operates on visible bars.
    • Avoid emitting cursor-up escape sequences when lastBarsCount is 0.
  • Update Pool.writer to ensure first is updated on the initial tick.
  • Add regression test suite in v3/pool_test.go verifying single-bar and multi-bar pool cleanups, redraw cycle line clearing, cursor repositioning, and concurrent worker updates.

Fixes #223.

When progress bars within a Pool have CleanOnFinish enabled, finishing
bars or stopping the pool failed to clear completed bar lines during redraw
cycles. The pool print routine unconditionally rendered all bars and left
trailing output when the number of visible bars decreased.

Update Pool.print to:
- Filter out completed bars where CleanOnFinish is true.
- Clear trailing lines with blank spaces when active bar count decreases.
- Reposition cursor back to the bottom of the remaining active bars.
- Properly update lastBarsCount and prune finished CleanOnFinish bars.
- Add regression tests covering single-bar and multi-bar pool cleanups.

Fixes cheggaaa#223.
@AdamMagued

Copy link
Copy Markdown
Author

Closing in favor of maintainer PR #249 to keep the review queue clean.

@AdamMagued AdamMagued closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CleanOnFinish doesn't work as intended in pool

1 participant