ShellProgressBar 5.1.0
See the version list below for details.
dotnet add package ShellProgressBar --version 5.1.0
NuGet\Install-Package ShellProgressBar -Version 5.1.0
<PackageReference Include="ShellProgressBar" Version="5.1.0" />
paket add ShellProgressBar --version 5.1.0
#r "nuget: ShellProgressBar, 5.1.0"
// Install ShellProgressBar as a Cake Addin #addin nuget:?package=ShellProgressBar&version=5.1.0 // Install ShellProgressBar as a Cake Tool #tool nuget:?package=ShellProgressBar&version=5.1.0
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
and Windows
(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");
}
Reporting progression
There are two ways to report progression. You can use the Tick()
function as described above. Alternatively you can report progression through an IProgress<T>
instance that you obtain by calling AsProgress<T>()
on the progress bar object.
For a simple case where the progress type is a float
value between 0.0 and 1.0 that represents the completion percentage, use progressBar.AsProgress<float>()
:
using ProgressBar progressBar = new ProgressBar(10000, "My Progress Message");
IProgress progress = progressBar.AsProgress<float>();
progress.Report(0.25); // Advances the progress bar to 25%
See IntegrationWithIProgressExample.cs
and IntegrationWithIProgressPercentageExample.cs
in the src/ShellProgressBar.Example/Examples directory for full examples.
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.
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.
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
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);
}
});
}
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
};
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 Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net46 was computed. net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
- System.Text.Encoding.CodePages (>= 4.0.1)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
- System.Text.Encoding.CodePages (>= 4.0.1)
-
.NETStandard 2.0
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
- System.Text.Encoding.CodePages (>= 4.0.1)
NuGet packages (14)
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
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. |
|
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. |
|
Chiron.Cli.Lab
Lab Chiron CLI components. |
|
Catalyst.Tools.Importer
Package Description |
GitHub repositories (13)
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!
|
|
bezzad/Downloader
Fast, cross-platform and reliable multipart downloader with asynchronous progress events for .NET applications.
|
|
takuya-takeuchi/FaceRecognitionDotNet
The world's simplest facial recognition api for .NET on Windows, MacOS and Linux
|
|
Reloaded-Project/Reloaded-II
Universal .NET Core Powered Modding Framework for any Native Game X86, X64.
|