Skip to content

Commit

Permalink
Feature/dotnet core (#14)
Browse files Browse the repository at this point in the history
* started on porting this to .netstandard 1.3

* updated progressbar to be displayed correctly on OSX with the help of #12, finally able to find the time to whip out the macbook :)

* updated fixes for OSX from #12 to not bite windows

* xmldocs and nuget info in csproj

* update build.bat to quickly build/release'

* Added coding examples for the various options which will make it into to the README as gifs shortly

* finished adding examples to support documentation

* indentation
  • Loading branch information
Mpdreamz authored Nov 12, 2017
1 parent 8d7e166 commit d0481de
Show file tree
Hide file tree
Showing 36 changed files with 471 additions and 432 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root=true

[*.cs]
trim_trailing_whitespace=true
insert_final_newline=true

[*]
indent_style = tab
indent_size = 4

[*.cshtml]
indent_style = tab
indent_size = 4

[*.{fs,fsx}]
indent_style = space
indent_size = 4

[*.{md,markdown,json,js,csproj,fsproj,targets}]
indent_style = space
indent_size = 2
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.suo
*.user
*.sln.docstates
.idea

# Build results

Expand Down Expand Up @@ -153,4 +154,4 @@ build/tmp/*
build/_out/*
!build/keys
!build/tools/*
!build/tools/scriptcs/*
!build/tools/scriptcs/*
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,17 @@ ShellProgressBar - display progress in your console application

# Install

Get it on nuget:

http://www.nuget.org/packages/ShellProgressBar/
Get it on nuget: http://www.nuget.org/packages/ShellProgressBar/

# Usage

Usage is really straightforward

```
var maxTicks = 9000;
using (var pbar = new ProgressBar(maxTicks, "Starting", ConsoleColor.Cyan, '\u2593'))
{
for (var i = 0; i<maxTicks; i++)
{
pbar.Tick("Currently processing " + i);
}
}
```


### Credits

The bulk of the code was taken from this article:
The initial implementation was inspired by this article.
http://www.bytechaser.com/en/articles/ckcwh8nsyt/display-progress-bar-in-console-application-in-c.aspx
13 changes: 11 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
"C:\Program Files (x86)\MSBuild\14.0\Bin\MsBuild.exe" ^
build\Build.proj /p:NuspecFile=build\ShellProgressBar.nuspec;BUILD_NUMBER=%1 /t:NugetPackage
@ECHO OFF

pushd src

dotnet restore

IF "%~1"=="" ( dotnet build )
IF NOT "%~1"=="" ( dotnet pack -c Release /p:Version=%1 )

popd

73 changes: 0 additions & 73 deletions build/Build.proj

This file was deleted.

22 changes: 0 additions & 22 deletions build/ShellProgressBar.nuspec

This file was deleted.

6 changes: 0 additions & 6 deletions src/ShellProgressBar.Example/App.config

This file was deleted.

34 changes: 34 additions & 0 deletions src/ShellProgressBar.Example/Examples/ChildrenExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace ShellProgressBar.Example.Examples
{
public class ChildrenExample : ExampleBase
{
protected override void Start()
{
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);
}
});
}
}
}
}
35 changes: 35 additions & 0 deletions src/ShellProgressBar.Example/Examples/ChildrenNoCollapseExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace ShellProgressBar.Example.Examples
{
public class ChildrenNoCollapseExample : ExampleBase
{
protected override void Start()
{
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 = '─',
CollapseWhenFinished = false
};
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);
}
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ShellProgressBar.Example.Examples
{
public class DontDisplayInRealTimeExample : ExampleBase
{
protected override void Start()
{
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);
}
}
}
}
34 changes: 34 additions & 0 deletions src/ShellProgressBar.Example/Examples/ExampleBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace ShellProgressBar.Example.Examples
{
public abstract class ExampleBase : IProgressBarExample
{
private bool RequestToQuit { get; set; }

protected void TickToCompletion(IProgressBar pbar, int ticks, int sleep = 1750, Action childAction = null)
{
var initialMessage = pbar.Message;
for (var i = 0; i < ticks && !RequestToQuit; i++)
{
pbar.Message = $"Start {i + 1} of {ticks}: {initialMessage}";
childAction?.Invoke();
Thread.Sleep(sleep);
pbar.Tick($"End {i + 1} of {ticks}: {initialMessage}");
}
}

public Task Start(CancellationToken token)
{
RequestToQuit = false;
token.Register(() => RequestToQuit = true);

this.Start();
return Task.FromResult(1);
}

protected abstract void Start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace ShellProgressBar.Example.Examples
{
public class ProgressBarOnBottomExample : ExampleBase
{
protected override void Start()
{
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);
}
}
}
}
23 changes: 23 additions & 0 deletions src/ShellProgressBar.Example/Examples/StylingExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace ShellProgressBar.Example.Examples
{
public class StylingExample : ExampleBase
{
protected override void Start()
{
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);
}
}
}
}
Loading

0 comments on commit d0481de

Please sign in to comment.