-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
120 additions
and
15 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
54 changes: 54 additions & 0 deletions
54
src/ShellProgressBar.Example/Examples/PersistMessageExample.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,54 @@ | ||
using System; | ||
using System.Threading; | ||
|
||
namespace ShellProgressBar.Example.Examples | ||
{ | ||
public class PersistMessageExample : ExampleBase | ||
{ | ||
protected override void Start() | ||
{ | ||
var options = new ProgressBarOptions | ||
{ | ||
ForegroundColor = ConsoleColor.Yellow, | ||
ForegroundColorDone = ConsoleColor.DarkGreen, | ||
BackgroundColor = ConsoleColor.DarkGray, | ||
BackgroundCharacter = '\u2593', | ||
WriteQueuedMessage = message => { | ||
if (message.StartsWith("Report 500")) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.DarkRed; | ||
Console.WriteLine("Add an extra message, because why not"); | ||
|
||
Console.ForegroundColor = ConsoleColor.Blue; | ||
Console.WriteLine(message); | ||
return 2; //signal to the progressbar we wrote two messages | ||
} | ||
Console.ForegroundColor = ConsoleColor.Blue; | ||
Console.WriteLine(message); | ||
return 1; | ||
} | ||
}; | ||
var wait = TimeSpan.FromSeconds(5); | ||
using (var pbar = new FixedDurationBar(wait, "", options)) | ||
{ | ||
var t = new Thread(()=> LongRunningTask(pbar)); | ||
t.Start(); | ||
|
||
if (!pbar.CompletedHandle.WaitOne(wait)) | ||
Console.Error.WriteLine($"{nameof(FixedDurationBar)} did not signal {nameof(FixedDurationBar.CompletedHandle)} after {wait}"); | ||
|
||
} | ||
} | ||
|
||
private static void LongRunningTask(FixedDurationBar bar) | ||
{ | ||
for (var i = 0; i < 1_000_000; i++) | ||
{ | ||
bar.Message = $"{i} events"; | ||
if (bar.IsCompleted) break; | ||
if (i % 500 == 0) bar.WriteLine($"Report {i} to console above the progressbar"); | ||
Thread.Sleep(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
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
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
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
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
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