ShellProgressBar 4.3.0

.NET Standard 1.3
There is a newer version of this package available.
See the version list below for details.
Install-Package ShellProgressBar -Version 4.3.0
dotnet add package ShellProgressBar --version 4.3.0
<PackageReference Include="ShellProgressBar" Version="4.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ShellProgressBar --version 4.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ShellProgressBar, 4.3.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install ShellProgressBar as a Cake Addin
#addin nuget:?package=ShellProgressBar&version=4.3.0

// Install ShellProgressBar as a Cake Tool
#tool nuget:?package=ShellProgressBar&version=4.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ShellProgressBar

visualize (concurrent) progress in your console application

This is a great little library to visualize long running command line tasks.

.NET Core ready!

It also supports spawning child progress bars which allows you to visualize dependencies and concurrency rather nicely.

Tested on OSX

example osx

and Windows

example win cmd

(Powershell works too, see example further down)

Install

Get it on nuget: http://www.nuget.org/packages/ShellProgressBar/

Usage

Usage is really straightforward

const int totalTicks = 10;
var options = new ProgressBarOptions
{
    ProgressCharacter = '─',
    ProgressBarOnBottom = true
};
using (var pbar = new ProgressBar(totalTicks, "Initial message", options))
{
    pbar.Tick(); //will advance pbar to 1 out of 10.
    //we can also advance and update the progressbar text
    pbar.Tick("Step 2 of 10"); 
}

Options

Progress bar position

const int totalTicks = 10;
var options = new ProgressBarOptions
{
	ProgressCharacter = '─',
	ProgressBarOnBottom = true
};
using (var pbar = new ProgressBar(totalTicks, "progress bar is on the bottom now", options))
{
	TickToCompletion(pbar, totalTicks, sleep: 500);
}

By default the progress bar is at the top and the message at the bottom. This can be flipped around if so desired.

bar_on_bottom

Styling changes

const int totalTicks = 10;
var options = new ProgressBarOptions
{
	ForegroundColor = ConsoleColor.Yellow,
	ForegroundColorDone = ConsoleColor.DarkGreen,
	BackgroundColor = ConsoleColor.DarkGray,
	BackgroundCharacter = '\u2593'
};
using (var pbar = new ProgressBar(totalTicks, "showing off styling", options))
{
	TickToCompletion(pbar, totalTicks, sleep: 500);
}

Many aspects can be styled including foreground color, background (inactive portion) and changing the color on completion.

styling

No real time update

By default a timer will draw the screen every 500ms. You can configure the progressbar to only be drawn when .Tick() is called.

const int totalTicks = 5;
var options = new ProgressBarOptions
{
	DisplayTimeInRealTime = false
};
using (var pbar = new ProgressBar(totalTicks, "only draw progress on tick", options))
{
	TickToCompletion(pbar, totalTicks, sleep:1750);
}

If you look at the time passed you will see it skips 02:00

update_on_tick

Descendant progressbars

A progressbar can spawn child progress bars and each child can spawn its own progressbars. Each child can have its own styling options.

This is great to visualize concurrent running tasks.

const int totalTicks = 10;
var options = new ProgressBarOptions
{
	ForegroundColor = ConsoleColor.Yellow,
	BackgroundColor = ConsoleColor.DarkYellow,
	ProgressCharacter = '─'
};
var childOptions = new ProgressBarOptions
{
	ForegroundColor = ConsoleColor.Green,
	BackgroundColor = ConsoleColor.DarkGreen,
	ProgressCharacter = '─'
};
using (var pbar = new ProgressBar(totalTicks, "main progressbar", options))
{
	TickToCompletion(pbar, totalTicks, sleep: 10, childAction: () =>
	{
		using (var child = pbar.Spawn(totalTicks, "child actions", childOptions))
		{
			TickToCompletion(child, totalTicks, sleep: 100);
		}
	});
}

children

By default children will collapse when done, making room for new/concurrent progressbars.

You can keep them around by specifying CollapseWhenFinished = false

var childOptions = new ProgressBarOptions
{
	ForegroundColor = ConsoleColor.Green,
	BackgroundColor = ConsoleColor.DarkGreen,
	ProgressCharacter = '─',
	CollapseWhenFinished = false
};

children_no_collapse

FixedDurationBar

ProgressBar is great for visualizing tasks with an unknown runtime. If you have a task that you know takes a fixed amount of time there is also a FixedDurationBar subclass. FixedDurationBar will Tick() automatically but other then that all the options and usage are the same. Except it relies on the real time update feature so disabling that will throw.

FixedDurationBar exposes an IsCompleted and CompletedHandle

Credits

The initial implementation was inspired by this article. http://www.bytechaser.com/en/articles/ckcwh8nsyt/display-progress-bar-in-console-application-in-c.aspx

And obviously anyone who sends a PR to this repository 👍

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Universal Windows Platform uap uap10.0
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (9)

Showing the top 5 NuGet packages that depend on ShellProgressBar:

Package Downloads
TIKSN-Framework

This is a .NET Framework enhancement framework. Main features are Versioning, Finance, Currency, Foreign Exchange, Money, Pricing strategy, Telemetry, Composite Weighted Progress, Repository and Unity of Wok pattern implementation with Entity Framework Core, Network Connectivity Service and Triggering, Settings, Windows Registry configuration source, Azure Storage Repository, MongoDB Repository, NoDB Repository, Lingual and Regional Localization, Serialization, Rest Requester, Rest Repository, Dependency Injection, Composition Root Setup base classes.

Microsoft.CST.ApplicationInspector.Commands The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Microsoft Application Inspector is a software source code analysis tool that helps identify and surface well-known features and other interesting characteristics of source code to aid in determining what the software is or what it does.

Catalyst.Tools.Importer

Package Description

stryker

All stryker mutation test logic is contained in this library. This package does not include a runner. Use this package if you want to extend stryker with your own runner.

ConsoleStyle

Package Description

GitHub repositories (7)

Showing the top 5 popular GitHub repositories that depend on ShellProgressBar:

Repository Stars
microsoft/ApplicationInspector
A source code analyzer built for surfacing features of interest and other characteristics to answer the question 'What's in the code?' quickly using static analysis with a json based rules engine. Ideal for scanning components before use or detecting feature level changes.
stryker-mutator/stryker-net
Mutation testing for .NET core and .NET framework!
takuya-takeuchi/FaceRecognitionDotNet
The world's simplest facial recognition api for .NET on Windows, MacOS and Linux
bezzad/Downloader
Fast and reliable multipart downloader with asynchronous progress events for .NET applications.
planetarium/NineChronicles
Unity client application for Nine Chronicles, a fully decentralized idle RPG powered by the community.
Version Downloads Last updated
5.1.0 218,816 1/29/2021
5.0.0 336,173 2/23/2020
4.3.0 161,213 8/20/2019
4.2.0 166,972 8/25/2018
4.1.1 4,326 8/15/2018
4.0.0 46,190 11/12/2017
3.0.0 106,190 4/11/2016
1.2.0 16,654 8/26/2015
1.1.0 9,507 6/19/2014
1.0.0 6,626 11/14/2013