-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support sub progressbars to any depth
- Loading branch information
Showing
26 changed files
with
897 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" ^ | ||
"C:\Program Files (x86)\MSBuild\14.0\Bin\MsBuild.exe" ^ | ||
build\Build.proj /p:NuspecFile=build\ShellProgressBar.nuspec;BUILD_NUMBER=%1 /t:NugetPackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/ShellProgressBar.Example/Examples/DeeplyNestedProgressBarTreeExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class DeeplyNestedProgressBarTreeExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var random = new Random(); | ||
|
||
var numberOfSteps = 7; | ||
|
||
var overProgressOptions = new ProgressBarOptions | ||
{ | ||
BackgroundColor = ConsoleColor.DarkGray, | ||
}; | ||
|
||
using (var pbar = new ProgressBar(numberOfSteps, "overal progress", overProgressOptions)) | ||
{ | ||
var stepBarOptions = new ProgressBarOptions | ||
{ | ||
ForeGroundColor = ConsoleColor.Cyan, | ||
ForeGroundColorDone = ConsoleColor.DarkGreen, | ||
ProgressCharacter = '─', | ||
BackgroundColor = ConsoleColor.DarkGray, | ||
CollapseWhenFinished = false, | ||
|
||
} ; | ||
Parallel.For(0, numberOfSteps, (i) => | ||
{ | ||
var workBarOptions = new ProgressBarOptions | ||
{ | ||
ForeGroundColor = ConsoleColor.Yellow, | ||
ProgressCharacter = '─', | ||
BackgroundColor = ConsoleColor.DarkGray, | ||
}; | ||
var childSteps = random.Next(1, 5); | ||
using (var childProgress = pbar.Spawn(childSteps, $"step {i} progress", stepBarOptions)) | ||
Parallel.For(0, childSteps, (ci) => | ||
{ | ||
var childTicks = random.Next(50, 250); | ||
using (var innerChildProgress = childProgress.Spawn(childTicks, $"step {i}::{ci} progress", workBarOptions)) | ||
{ | ||
for (var r = 0; r < childTicks; r++) | ||
{ | ||
innerChildProgress.Tick(); | ||
Program.BusyWait(50); | ||
} | ||
} | ||
childProgress.Tick(); | ||
}); | ||
|
||
pbar.Tick(); | ||
}); | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/ShellProgressBar.Example/Examples/DrawsOnlyOnTickExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class DrawsOnlyOnTickExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 5; | ||
var updateOnTicksOnlyOptions = new ProgressBarOptions {DisplayTimeInRealTime = false}; | ||
using (var pbar = new ProgressBar(ticks, "only update time on ticks", updateOnTicksOnlyOptions)) | ||
{ | ||
for (var i = 0; i < ticks; i++) | ||
{ | ||
pbar.Tick("only update time on ticks, current: " + i); | ||
Thread.Sleep(1750); | ||
} | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/ShellProgressBar.Example/Examples/LongRunningExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class LongRunningExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 100; | ||
using (var pbar = new ProgressBar(ticks, "my long running operation", ConsoleColor.Green)) | ||
{ | ||
for (var i = 0; i < ticks; i++) | ||
{ | ||
pbar.Tick("step " + i); | ||
Thread.Sleep(50); | ||
} | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/ShellProgressBar.Example/Examples/NegativeMaxTicksExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class NegativeMaxTicksExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = -100; | ||
using (var pbar = new ProgressBar(ticks, "my operation with negative ticks", ConsoleColor.Cyan)) | ||
{ | ||
for (var i = 0; i < ticks; i++) | ||
{ | ||
pbar.Tick("step " + i); | ||
Thread.Sleep(50); | ||
} | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/ShellProgressBar.Example/Examples/NestedProgressBarPerStepProgress.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class NestedProgressBarPerStepProgress : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var outerTicks = 10; | ||
using (var pbar = new ProgressBar(outerTicks, "outer progress", ConsoleColor.Cyan)) | ||
{ | ||
for (var i = 0; i < outerTicks; i++) | ||
{ | ||
InnerProgressBars(pbar); | ||
pbar.Tick(); | ||
} | ||
} | ||
return Task.FromResult(1); | ||
} | ||
|
||
private static void InnerProgressBars(ProgressBar pbar) | ||
{ | ||
var innerProgressBars = Enumerable.Range(0, new Random().Next(2, 6)) | ||
.Select(s => pbar.Spawn(new Random().Next(2, 5), $"inner bar {s}")) | ||
.ToList(); | ||
|
||
var maxTicks = innerProgressBars.Max(p => p.MaxTicks); | ||
|
||
for (var ii = 0; ii < maxTicks; ii++) | ||
{ | ||
foreach (var p in innerProgressBars) | ||
{ | ||
InnerInnerProgressBars(p); | ||
p.Tick(); | ||
} | ||
|
||
|
||
Thread.Sleep(4); | ||
} | ||
foreach (var p in innerProgressBars) p.Dispose(); | ||
} | ||
|
||
private static void InnerInnerProgressBars(ChildProgressBar pbar) | ||
{ | ||
var progressBarOption = new ProgressBarOptions { ForeGroundColor = ConsoleColor.Yellow }; | ||
var innerProgressBars = Enumerable.Range(0, new Random().Next(1, 3)) | ||
.Select(s => pbar.Spawn(new Random().Next(5, 10), $"inner bar {s}", progressBarOption)) | ||
.ToList(); | ||
if (!innerProgressBars.Any()) return; | ||
|
||
var maxTicks = innerProgressBars.Max(p => p.MaxTicks); | ||
|
||
for (var ii = 0; ii < maxTicks; ii++) | ||
{ | ||
foreach (var p in innerProgressBars) | ||
p.Tick(); | ||
} | ||
foreach (var p in innerProgressBars) p.Dispose(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/ShellProgressBar.Example/Examples/NeverCompletesExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class NeverCompletesExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 5; | ||
using (var pbar = new ProgressBar(ticks, "A console progress bar does not complete")) | ||
{ | ||
pbar.Tick(); | ||
pbar.Tick(); | ||
pbar.Tick(); | ||
pbar.Tick(); | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/ShellProgressBar.Example/Examples/NeverTicksExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class NeverTicksExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 10; | ||
using (var pbar = new ProgressBar(ticks, "A console progress bar that never ticks")) | ||
{ | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/ShellProgressBar.Example/Examples/ThreadedTicksOverflowExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class ThreadedTicksOverflowExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 200; | ||
using (var pbar = new ProgressBar(ticks/10, "My operation that ticks to often using threads", ConsoleColor.Cyan)) | ||
{ | ||
var threads = Enumerable.Range(0, ticks).Select(i => new Thread(() => pbar.Tick("threaded tick " + i))).ToList(); | ||
foreach (var thread in threads) thread.Start(); | ||
foreach (var thread in threads) thread.Join(); | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/ShellProgressBar.Example/Examples/TicksOverflowExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class TicksOverflowExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 10; | ||
using (var pbar = new ProgressBar(ticks, "My operation that ticks to often", ConsoleColor.Cyan)) | ||
{ | ||
for (var i = 0; i < ticks*10; i++) | ||
{ | ||
pbar.Tick("too many steps " + i); | ||
Thread.Sleep(50); | ||
} | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/ShellProgressBar.Example/Examples/UpdatesMaxTicksExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class UpdatesMaxTicksExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 10; | ||
using (var pbar = new ProgressBar(ticks, "My operation that updates maxTicks", ConsoleColor.Cyan)) | ||
{ | ||
var sleep = 1000; | ||
for (var i = 0; i < ticks; i++) | ||
{ | ||
pbar.Tick("Updating maximum ticks " + i); | ||
if (i == 5) | ||
{ | ||
ticks = 120; | ||
pbar.UpdateMaxTicks(ticks); | ||
sleep = 50; | ||
} | ||
Thread.Sleep(sleep); | ||
} | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/ShellProgressBar.Example/Examples/ZeroMaxTicksExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class ZeroMaxTicksExample : IProgressBarExample | ||
{ | ||
public Task Start(CancellationToken token) | ||
{ | ||
var ticks = 0; | ||
using (var pbar = new ProgressBar(ticks, "my operation with zero ticks", ConsoleColor.Cyan)) | ||
{ | ||
for (var i = 0; i < ticks; i++) | ||
{ | ||
pbar.Tick("step " + i); | ||
Thread.Sleep(50); | ||
} | ||
} | ||
return Task.FromResult(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShellProgressBar.Example | ||
{ | ||
public interface IProgressBarExample | ||
{ | ||
Task Start(CancellationToken token); | ||
} | ||
} |
Oops, something went wrong.