ErikForwerk.ConsoleTools.ProgressBar
1.0.3
dotnet add package ErikForwerk.ConsoleTools.ProgressBar --version 1.0.3
NuGet\Install-Package ErikForwerk.ConsoleTools.ProgressBar -Version 1.0.3
<PackageReference Include="ErikForwerk.ConsoleTools.ProgressBar" Version="1.0.3" />
<PackageVersion Include="ErikForwerk.ConsoleTools.ProgressBar" Version="1.0.3" />
<PackageReference Include="ErikForwerk.ConsoleTools.ProgressBar" />
paket add ErikForwerk.ConsoleTools.ProgressBar --version 1.0.3
#r "nuget: ErikForwerk.ConsoleTools.ProgressBar, 1.0.3"
#:package ErikForwerk.ConsoleTools.ProgressBar@1.0.3
#addin nuget:?package=ErikForwerk.ConsoleTools.ProgressBar&version=1.0.3
#tool nuget:?package=ErikForwerk.ConsoleTools.ProgressBar&version=1.0.3
Console Progress Bar
Current Status
Table of Contents
Basics
This project provides functions to easily and conveniently display a progress bar in a C# console window when iterating over an enumeration. (similar to tqdm
in python)
This is a private project and was mainly done for fun and learning purposes. It is not intended to be used in production code.
using ConsoleProgressBar;
int[] numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
foreach (int number in numbers.ConsoleProgress())
{
// Do something with the number
}
Styling
There are different predefined styles and color sets that can be used to change the appearance of the progress bar. All default styles can be accessed through the ConsoleProgressStyle
class.
foreach (int number in numbers
.ConsoleProgress()
.WithStyle(ConsoleProgressStyle.Millennium) )
{
// Do something with the number
}
Of course it is possible to define own custom styles using the ConsoleProgressStyle
class.
var customStyle = new ConsoleProgressStyle(true, true, ">>", "<<", '*', '#', FractionsSets.AnimationCircle),
foreach (int number in numbers
.ConsoleProgress()
.WithStyle(customStyle) )
{
// Do something with the number
}
Colors
You can apply different color sets to the progress bar using the .WithColors(…)
. All default color sets can be accessed through the ConsoleProgressColors
class.
foreach (int number in numbers
.ConsoleProgress()
.WithColors(ConsoleProgressColors.Red) )
{
// your code here
}
Colors can also be customized using the .WithColor(…)
and .WithBgColor(…)
extension methods.
foreach (int number in numbers
.ConsoleProgress()
.WithColor(ConsoleColor.Blue, ConsoleColor.Cyan, ConsoleColor.DarkGray)
.WithBgColor(ConsoleColor.Red) )
{
// your code here
}
Random Examples
The example console application ConsoleExample
shows some random combinations of the available styles and colors for the progress bar.
Additional Features
When iterating over huge external data (e.g. entity framework table rows) it might be useful to provide the progress bar with the total number of elements to be processed. This can be done by providing the total number of elements with .WithPreCount(…)
extension method.
This will prevent the progress bar from trying to count the elements itself which all items to be iterated over which in turn will lead to executing the DB query twice.
For debugging it might be useful to cancel the iteration after a certain number of elements. This can be done by providing the maximum number of elements with .CancelAfter(…)
extension method.
For testing purposes, there is the extension method .WithDebugMode()
which will prevent the progress bar from trying to read the window size and cursor positions which might not work in the testing environment.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.