Skip to content

Simple progress indicator for console .NET projects.

License

Notifications You must be signed in to change notification settings

filipliwinski/SimpleConsoleProgress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleConsoleProgress

Free and open-source library with a simple progress indicator for .NET console projects.

Build Status CodeQL Coverage Quality Gate Status

Support for .NET Framework (4.5+), .NET Core and .NET.

Download from NuGet.

NuGet NuGet

How to use

using SimpleConsoleProgress;

Single-line progress bar

The progress bar is updated in one line. Use it if the progress is the only output in the process.

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total);
}
Console.WriteLine("Process completed.");

Multiline progress bar

Each progress update is written on a new line.

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.WriteLine(i, total);
}
Console.WriteLine("Process completed.");

No progress bar

Shows just the progress value.

var total = 20;
for (int i = 0; i < total; i++)
{
    Progress.Write(i, total);
}
Console.WriteLine("Process completed.");

Options

Show elapsed time

You can provide a TimeSpan object with the time to show next to the progress bar. SimpleConsoleProgress does not include any timers, to be as simple as possible.

var total = 20;
var timer = new Stopwatch();
timer.Start();
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, timer.Elapsed);
}
Console.WriteLine("Process completed.");

Custom progress indicator

By default, '#' is used as a progress indicator. You can change it with any character you want.

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, character: '>');
}
Console.WriteLine("Process completed.");

Autohide progress bar (single-line)

By default, single-line progress bar persists in the output. You can hide it when it completes.

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, autoHide: true);
}
Console.WriteLine("Process completed.");

Size

Use one of four different bar sizes. By default the progress bar size is set to Full - the full width of the console window.

Size - Small (16 characters)

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, size: BarSize.Small);
}
Console.WriteLine("Process completed.");
Size - Medium (40 characters)

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, size: BarSize.Medium);
}
Console.WriteLine("Process completed.");
Size - Big (88 characters)

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, size: BarSize.Big);
}
Console.WriteLine("Process completed.");

Percent value location

The current percentage is displayed by default in the middle of the progress bar. It can be on the left / right side of the progress bar or it can be hidden.

Location - left

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, location: PercentLocation.Left);
}
Console.WriteLine("Process completed.");
Location - right

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, location: PercentLocation.Right);
}
Console.WriteLine("Process completed.");
Location - none

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, location: PercentLocation.None);
}
Console.WriteLine("Process completed.");

Accuracy

By default, integer values are displayed. You can increase the accuracy to three decimal places.

Accuracy - one decimal place

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, accuracy: 1);
}
Console.WriteLine("Process completed.");
Accuracy - two decimal places

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, accuracy: 2);
}
Console.WriteLine("Process completed.");
Accuracy - three decimal places

var total = 20;
for (int i = 0; i < total; i++)
{
    ProgressBar.Write(i, total, accuracy: 3);
}
Console.WriteLine("Process completed.");