feat(*): Add inline progress utility

This is a customised version of the one used in the YouTubeExplode converter windows app, that now only prints when there's a new number, in order to get it to work better using docker logs to monitor it rather than an actual console.
This commit is contained in:
Josh Creek
2021-08-29 15:42:33 +01:00
parent 641456f293
commit 6e99d19fe4
@@ -0,0 +1,35 @@
using System;
namespace YouTubeChannelDownloader.Utilities
{
internal class InlineProgress : IProgress<double>, IDisposable
{
private readonly int _posX;
private readonly int _posY;
private string lastProgressPrint = string.Empty;
public InlineProgress()
{
_posX = Console.CursorLeft;
_posY = Console.CursorTop;
}
public void Report(double progress)
{
string currentProgress = $"{progress:P1}";
if (currentProgress != lastProgressPrint)
{
Console.SetCursorPosition(_posX, _posY);
Console.WriteLine(currentProgress);
lastProgressPrint = currentProgress;
}
}
public void Dispose()
{
Console.SetCursorPosition(_posX, _posY);
Console.WriteLine("Completed ✓");
}
}
}