mirror of
https://github.com/apple/container.git
synced 2026-09-05 23:35:43 +00:00
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:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user