Progress.swift ⌛ Add beautiful progress bars to your loops.

Overview

Progress.swift

Build Status codecov.io Carthage compatible SPM ready Version License Platform

demo gif

Just wrap the SequenceType in your loop with the Progress SequenceType and you'll automatically get beautiful progress bars.

Updating the progress bar does not work in the Xcode console because it does not support the cursor movements. If you want it to look nice run it in a real terminal.

Example

Just take a regular loop like this for i in 1...9 { ... and wrap the 1...9 range in the Progress type and you'll automatically get a nice progress bar.

import Progress

for i in Progress(1...9) {
    ...
}

Creates this output:

$ 4 of 9 [-------------                 ] ETA: 0:00:05 (at 1.01 it/s)

It also works with all the other types adopting the CollectionType protocol like dictionarys: Progress(["key": "value", "key2": "also value"]) and arrays: Progress([1, 52, 6, 26, 1]).

You can also create the progress bar manually without a sequence type:

var bar = ProgressBar(count: 4)

for i in 0...3 {
    bar.next()
    sleep(1)
}

Configuration

You can configure the progress bar by combining single building blocks of type ProgressElementType.

Either by setting a default configuration:

ProgressBar.defaultConfiguration = [ProgressString(string: "Percent done:"), ProgressPercent()]

which creates the following result:

$ Percent done: 80%

or by providing a specific configuration in the Process initializer:

Progress(0...10, configuration: [ProgressPercent(), ProgressBarLine(barLength: 60)])

resulting in something like this:

$ 100% [------------------------------------------------------------]

Available ProgressElementType elements:

  • ProgressBarLine (The actual bar. E.g. "[---------------------- ]").
  • ProgressIndex (The current index & overall count. E.g. "2 of 3").
  • ProgressPercent (The progress in percent. E.g. "60%").
  • ProgressTimeEstimates (Estimated time remaining & items per second. E.g. "ETA: 00:00:02 (at 1.00 it/s)").
  • ProgressString (Adds an arbitrary string to the progress bar).

Installation

Cocoapods

Progress.swift is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Progress.swift"

Carthage

To integrate Progress.swift into your Xcode project using Carthage, specify it in your Cartfile:

github "jkandzi/Progress.swift"

Run carthage update to build the framework and drag the built Progress.framework into your Xcode project.

Swift Package Manager

To install with the Swift Package Manager, add the following in your Package.swift:

import PackageDescription

let package = Package(
    name: "MyProject",
    dependencies: [
        .Package(url: "https://github.com/jkandzi/Progress.swift", majorVersion: 0)
    ]
)

Manual

You can also copy the Progress.swift file into your Xcode project.

Contribution

You are welcome to fork and submit pull requests.

Author

Justus Kandzi, [email protected]

License

Progress.swift is available under the MIT license. See the LICENSE file for more info.

Comments
  • Swift 5 Support

    Swift 5 Support

    Could there be a support for Swift 5?

    Currently, if you have another SPM with depends on Progress, on swift build command, you'll get:

    $>swift build
    [MyPersonalProjectPath]/.build/checkouts/Progress.swift: error: package at '[MyPersonalProjectPath]/.build/checkouts/Progress.swift' is using Swift tools version 3.1.0 which is no longer supported; use 4.0.0 or newer instead
    

    We can do swift package tools-version --set-current on the Progress folder, which will change in Package.swift:

    // swift-tools-version:4.0
    

    to:

    // swift-tools-version:5.0
    

    This can later be tested if you've cloned the Progress repository, then updated the swift-tools-version, and use:

    .package(path: "../[MyLocalPathToProgressWithSwiftToolVersionUpdate]/")
    

    instead of:

    .package(url: "https://github.com/jkandzi/Progress.swift.git", from: "0.3.0")
    

    While waiting for a 0.4.0 version.

    opened by afardel 2
  • Add support of Swift 4

    Add support of Swift 4

    Compilation time errors occur during project building with Swift 4.

    Just for instance:

    /depot/Learning/Progress.swift/Sources/Progress.swift:81:17: Overlapping accesses to 'self.printer', but modification requires exclusive access; consider copying to a local variable
    
    /depot/Learning/Progress.swift/Sources/Progress.swift:88:17: Overlapping accesses to 'self.printer', but modification requires exclusive access; consider copying to a local variable
    
    opened by botov 2
  • Makes the index, startTime, count public properties

    Makes the index, startTime, count public properties

    Makes the index, startTime, count public properties to allow better reuse outside the framework. In my case I wanted to add a custom printer in my application, and needed access to the index of the progress bar.

    opened by mz2 2
  • Swift 3.0

    Swift 3.0

    This is awesome project. It saved my lots of time to figure out hot to build a progress bar in cli. I'm glad to provide some little help to make this project able to support Swift-3.0.

    Oh.... I jumped build version to 0.2.0 because according http://semver.org/, upgrade language support is a big change but there is no release version above 1.0.0 so I suggest to jump version to change MINOR version.

    opened by Calvin-Huang 2
  • Print Statements are Sometimes Hidden

    Print Statements are Sometimes Hidden

    I'm running on Ubuntu 18.04 in tmux with Swift for Tensorflow 0.10:

    $ which swift
    /home/xander/swift-tensorflow-RELEASE-0.10-cuda10.2-cudnn7-ubuntu18.04/usr/bin/swift
    $ swift --version
    Swift version 5.3-dev (LLVM 55d27a5828, Swift 6a5d84ec08)
    Target: x86_64-unknown-linux-gnu
    

    When iterating quickly through ~1M items, I see this output:

    66324 of 1135979 [-                             ] ETA: 00:00:04 (at 220509.61) it/s)
    108336 of 1135979 [--                            ] ETA: 00:00:04 (at 216336.73) it/s)
    129321 of 1135979 [---                           ] ETA: 00:00:04 (at 215253.02) it/s)
    175216 of 1135979 [----                          ] ETA: 00:00:04 (at 218805.01) it/s)
    ERROR: 2233827600 != 707152639 - 4
    ERROR: 12597800 != 707152639 - 5
    ERROR: 2399647697 != 707152639 - 6
    ERROR: 3381059415 != 707152639 - 7
    801095 of 1135979 [---------------------         ] ETA: 00:00:01 (at 216461.09) it/s)
    842723 of 1135979 [----------------------        ] ETA: 00:00:01 (at 216034.35) it/s)
    1124439 of 1135979 [----------------------------- ] ETA: 00:00:00 (at 216200.51) it/s)
    

    Note that the above output isn't always the same. On different runs it may hide some of those ERROR statements.

    I was confused by this because I had a print statement in there that was being called but wasn't showing up in my terminal. So, doing the exact same run with the ProgressBar commented out, I see this:

    Successful checksum - 1
    Successful checksum - 2
    Successful checksum - 3
    ERROR: 2233827600 != 707152639 - 4
    ERROR: 12597800 != 707152639 - 5
    ERROR: 2399647697 != 707152639 - 6
    ERROR: 3381059415 != 707152639 - 7
    Successful checksum - 8
    Successful checksum - 9
    Successful checksum - 10
    

    This is the full print() output I expect.

    This also occurred on Ubuntu outside of tmux. Just ssh-ed into bash. I haven't attempted to reproduce on macOS.

    Hiding print statements is making it difficult to both debug a for loop at the same time I know how efficient my code is running inside the for loop.

    opened by xanderdunn 0
  • Iterations/second Should Average Over Recent History

    Iterations/second Should Average Over Recent History

    Thanks for making and maintaining this library, it's a much needed tool in Swift.

    It appears that the iterations/second is calculated based on some average of the speed from the entire history of the run? I believe most progress indicators prefer an average of recent history, rather than all history? In my current situation the progress iterations/second and ETA are working poorly for me because I must first iterate very quickly through ~80,000 items simply throwing them out until I find the starting location. Once I've found the starting location, iterating through the remaining ~900,000 items becomes much slower. Because the first 80,000 items are iterated extremely quickly compared to the remaining items, it will take ~5+ minutes for the iterations/second to average down to a number that is close to the true iterations per second after finding my stating location.

    If the progress bar were instead averaging on recent history, behavior should remain the same for situations where all iterations take the same amount of time, and it should become a more useful statistics for situations like mine where the speed of iteration changes.

    opened by xanderdunn 1
Releases(0.4.0)
Owner
Justus Kandzi
https://twitter.com/jkandzi
Justus Kandzi
Guaka - Smart and beautiful POSIX compliant CLI framework for Swift.

Guaka - Smart and beautiful POSIX compliant CLI framework for Swift. It helps you create modern and familiar CLI apps in the vein of widely used proje

Omar Abdelhafith 1.1k Dec 24, 2022
A command line tool that calls your Xcode Test Plan and creates screenshots of your app automatically.

ShotPlan (WIP) A command line tool that calls your Xcode Test Plan and creates screenshots of your app automatically. ShotPlan will also take care of

Devran Cosmo Uenal 6 Jul 21, 2022
Overlook - A commandline app that will watch your folder and monitor any changes

A commandline app that will watch your folder and monitor any changes. When a change occurs, Overlook will execute (or restart) a command you specify. Overlook is platform independent and will work with anything from writing a README file, to developing a service.

Wess Cope 150 Aug 9, 2022
Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement.

Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement. Supports Mac OS and Linux Line edit

Andy Best 114 Dec 14, 2022
Swift tool to generate Module Interfaces for Swift projects.

ModuleInterface Swift tool to generate Module Interfaces for Swift projects. What is a Module Interface A Module Interface is what we commonly get usi

Jorge Revuelta 75 Dec 21, 2022
Swift-cli - Example of building command-line tools in Swift

swift-cli Example of building command-line tools in Swift Step 1: Create CLI wit

Noah Gift 2 Jan 17, 2022
CommandLineKit - A pure Swift library for creating command-line interfaces

CommandLineKit A pure Swift library for creating command-line interfaces. Note: This project is no longer maintained. It's preserved here for historic

Ben Gollmer 1.1k Dec 1, 2022
Straightforward, type-safe argument parsing for Swift

Swift Argument Parser Usage Begin by declaring a type that defines the information that you need to collect from the command line. Decorate each store

Apple 2.9k Jan 7, 2023
SwiftCLI - A powerful framework for developing CLIs in Swift

SwiftCLI A powerful framework for developing CLIs, from the simplest to the most complex, in Swift.

Jake Heiser 793 Jan 4, 2023
SwiftShell - A Swift framework for shell scripting.

Run shell commands | Parse command line arguments | Handle files and directories Swift 5.1 - 5.3 | Swift 4 | Swift 3 | Swift 2 SwiftShell A library fo

Kare Morstol 973 Jan 2, 2023
SwiftyTextTable - A lightweight Swift library for generating text tables

SwiftyTextTable A lightweight Swift library for generating text tables. Swift Language Support SwiftyTextTable is now Swift 4.0 compatible! The last r

Scott Hoyt 283 Dec 23, 2022
Shell scripting in Swift

Shwift Shell-scripting in Swift DISCLAIMER: Shwift depends on Swift's incoming concurrency features. As such, it requires a recent Swift toolchain, an

George Lyon 32 Sep 15, 2022
Swift utilities for running commands.

Swift Commands Swift utilities for running commands. The Commands module allows you to take a system command as a string and return the standard outpu

Phil 41 Jan 2, 2023
A CLI too powered by Swift to provision environments using an up.toml manifest file

tuist-up tuist up was originally a Tuist built-in command to provision environments by reading the requirements in a manifest file Setup.swift. Althou

Tuist 5 Mar 31, 2022
Terminal string styling for Swift.

Terminal string styling for Swift. Integration Swift Package Manager (SPM) You can use The Swift Package Manager to install ColorizeSwift by adding it

Michał Tynior 281 Dec 22, 2022
Simple & Elegant Command Line Interfaces in Swift

An elegant pure Swift library for building command line applications. Features Tons of class, but no classes. 100% organic pure value types. Auto gene

hypertalk 52 Nov 9, 2022
✏️Expressive styling on terminal string. (chalk for swift)

Chalk Expressive styling on terminal string. Highlights Expressive API 256/TrueColor support Nest styles Auto downgrading to terminal supported color

Luo Xiu 59 Jun 10, 2022
A starting point to create CLI utilities with swift

cli tuist template A starting point to create CLI utilities with swift Installation Just create a Tuist folder and a Templates folder inside it. Creat

humdrum 6 May 3, 2022
A Tuist Template to quickly create CLI apps in Swift

macOS CLI Template Motivation I'm writing more and more Swift CLI apps these days. And as I solve more problems with this litte tools, I find that I'm

Diego Freniche 21 Dec 28, 2022