TQDMProgressBar is a Swift package that provides a customizable progress bar for command-line interfaces, inspired by Python's TQDM library. It offers a simple and flexible way to add progress indicators to your Swift applications.
- Easy to use with sequences, async sequences, and manual updates
- Customizable appearance with various styles and colors
- Support for different bar formats
- Unit scaling for easy representation of file sizes, etc.
- Async/await support for modern Swift concurrency
Add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/engali94/TQDMProgressBar.git", from: "0.1")
]
import TQDMProgressBar
let total = 100
let bar = ProgressBar(total: total, desc: "Processing")
for _ in 0..<total {
// Do some work
Thread.sleep(forTimeInterval: 0.1)
bar.update(1)
}
bar.close()
let numbers = Array(1...100)
let progressBar = ProgressBar(sequence: numbers, desc: "Processing")
for number in progressBar.iterate(numbers) {
// Process each number
Thread.sleep(forTimeInterval: 0.1)
}
let bar = ProgressBar(total: 100, desc: "Async processing")
try await bar.forEach {
try await someAsyncOperation()
}
var style = ProgressBarStyle.default
style.fill = "█"
style.emptyFill = "░"
style.barColor = .cyan
style.descColor = .green
let bar = ProgressBar(total: 100, desc: "Custom style", style: style)
// Use the bar...
init(total:desc:style:)
: Initialize a progress bar with a known totalinit(sequence:desc:style:)
: Initialize a progress bar for a sequenceupdate(_:)
: Update the progressclose()
: Close the progress barsetDescription(_:)
: Set a new descriptionsetPostfix(_:)
: Set a new postfixforEach(_:)
: Execute a closure for each iterationtrack(_:)
: Track progress of an async operation
barFormat
: Format of the progress barfill
: Character for filled portionemptyFill
: Character for empty portionbarColor
: Color of the bardescColor
: Color of the description
Contributions are welcome! Please feel free to submit a Pull Request.