-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathExampleBase.cs
33 lines (28 loc) · 915 Bytes
/
ExampleBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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<int> childAction = null)
{
var initialMessage = pbar.Message;
for (var i = 0; i < ticks && !RequestToQuit; i++)
{
pbar.Message = $"Start {i + 1} of {ticks} {Console.CursorTop}/{Console.WindowHeight}: {initialMessage}";
childAction?.Invoke(i);
Thread.Sleep(sleep);
pbar.Tick($"End {i + 1} of {ticks} {Console.CursorTop}/{Console.WindowHeight}: {initialMessage}");
}
}
public async Task Start(CancellationToken token)
{
RequestToQuit = false;
token.Register(() => RequestToQuit = true);
await this.StartAsync();
}
protected abstract Task StartAsync();
}
}