Ensure that the bar length never exceeds the remaining width (#1348)

- Fixes a reported problem, caused by a race in
  progress events from the Containerization package
  reaching container.
This commit is contained in:
Dmitry Kovba
2026-03-30 12:22:58 -07:00
committed by GitHub
parent 5fb62ab18c
commit 4a08bb0daa
2 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -235,7 +235,7 @@ extension ProgressBar {
if config.showProgressBar, total > 0, allowProgress {
let usedWidth = components.joined(separator: " ").count + 45
let remainingWidth = max(config.width - usedWidth, 1)
let barLength = state.finished ? remainingWidth : Int(Int64(remainingWidth) * value / total)
let barLength = min(remainingWidth, state.finished ? remainingWidth : Int(Int64(remainingWidth) * value / total))
let barPaddingLength = remainingWidth - barLength
let bar = "\(String(repeating: config.theme.bar, count: barLength))\(String(repeating: " ", count: barPaddingLength))"
components.append("|\(bar)|")
@@ -738,6 +738,17 @@ final class ProgressBarTests: XCTestCase {
XCTAssertEqual(output, "⠋ Task [0s]")
}
func testProgressBarSizeExceedsTotal() async throws {
let config = try ProgressConfig(
description: "Task",
showProgressBar: true,
totalSize: 50
)
let progress = ProgressBar(config: config)
progress.set(size: 100)
let _ = progress.draw()
}
func testItemsName() async throws {
let config = try ProgressConfig(
description: "Task",