Git Product home page Git Product logo

simpleconsoleprogress's Introduction

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.");

simpleconsoleprogress's People

Contributors

filipliwinski avatar

Stargazers

 avatar Ghazi Sarhan avatar helptiger avatar blaco avatar

Watchers

James Cloos avatar  avatar helptiger avatar

Forkers

b-hub

simpleconsoleprogress's Issues

autoHide issue

Hi @filipliwinski,

I have found an issue using autoHide: true if the console application is started using cmd.exe and /MIN option.
Please consider a new console application named SimpleConsoleProgressTest with this code in Program.cs:

// See https://aka.ms/new-console-template for more information
using SimpleConsoleProgress;

Console.WriteLine("Hello, World!");

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

Now start the application using this command:

> cmd.exe /C start ""  /MIN "SimpleConsoleProgressTest.exe"

The result is:

image

Have you any idea why using /MIN autoHide doesn't work?

Thank you for your support,
Filippo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.