Code Monkey home page Code Monkey logo

a-luna / console-progress-bar Goto Github PK

View Code? Open in Web Editor NEW
20.0 4.0 10.0 77 KB

Customizable progress bar for C# console applications (.NET Core 2.0). Includes a basic progress bar which can be used for any long-running task and a file transfer progress bar that detects when the transfer has stalled, firing an event that the client can subscribe to.

License: MIT License

C# 100.00%
consoleprogressbar net-core-2 net-core2 csharp transfer-files file-transfer progress-bar console-application console console-app console-visualization linux cross-platform c-sharp

console-progress-bar's Introduction

Progress Bar for Console Applications (.NET Core 2.0)

A simple way to represent the progress of a long-running task in a C# console app. Targets .NET Core 2.0.

Features

  • ConsoleProgressBar

    • Implements IProgress<double> The IProgress interface greatly simplifies the effort to report progress from an async method to the UI, clunky boilerplate code to ensure thread-safety is not required since the SynchronizationContext is captured when the progress bar is instantiated.
    • Efficient and light-weight Console can become sluggish and unresponsive when called frequently, this progress bar only performs 8 calls/second regardless of how often progress is reported.
    • Customizable Each component of the progress bar (start/end brackets, completed/incomplete blocks, progress animation) can be set to any string value through public properties and each item displayed (the progress bar itself, percentage complete, animation) can be shown or hidden.
  • FileTransferProgressBar

    • Extends ConsoleProgressBar and adds the ability to detect when a file transfer has stalled.
    • If the time since last progress reported exceeds the TimeSpanFileStalled value, the FileTransferStalled event fires.
    • Provides further customization of the display with the ability to show/hide the bytes received and file size in bytes

Examples

Windows

Progress Bar_Win

Mac (VS Code)

Progress Bar_Mac

Ubuntu

Progress Bar_Ubuntu

Usage

Numbers correspond to the examples shown above, full source code for examples can be found in ./TestConsole/Program.cs

// 1. Default behavior
var pb1 = new ConsoleProgressBar();
await TestProgressBar(pb1, 1);

// 2. Customized all progress bar components
var pb2 = new ConsoleProgressBar
{
    NumberOfBlocks = 18,
    StartBracket = string.Empty,
    EndBracket = string.Empty,
    CompletedBlock = "\u2022",
    IncompleteBlock = "·",
    AnimationSequence = ProgressAnimations.RotatingPipe
};
await TestProgressBar(pb2, 2);

// 3. Hide progress bar
var pb3 = new ConsoleProgressBar
{
    DisplayBar = false,
    AnimationSequence = ProgressAnimations.RotatingTriangle
};
await TestProgressBar(pb3, 3);

// 4. Customized progress bar, successful file transfer
const long fileSize = (long)(8 * FileHelper.OneKB);
var pb4 = new FileTransferProgressBar(fileSize, TimeSpan.FromSeconds(5))
{
    NumberOfBlocks = 15,
    StartBracket = "|",
    EndBracket = "|",
    CompletedBlock = "|",
    IncompleteBlock = "\u00a0",
    AnimationSequence = ProgressAnimations.PulsingLine
};
await TestFileTransferProgressBar(pb4, fileSize, 4);

// 5. Hide progress bar and animation, unsuccessful file transfer
const long fileSize2 = (long)(100 * 36 * FileHelper.OneMB);
var pb5 = new FileTransferProgressBar(fileSize2, TimeSpan.FromSeconds(5))
{
    DisplayBar = false,
    DisplayAnimation = false
};
pb5.FileTransferStalled += HandleFileTransferStalled;
await TestFileTransferStalled(pb5, fileSize2, 5);

console-progress-bar's People

Contributors

a-luna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.