From 6e99d19fe444dcb01bf3eae1c7d729c17efc25c5 Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Sun, 29 Aug 2021 15:42:33 +0100 Subject: [PATCH] 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. --- .../Utilities/InlineProgress.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 YouTubeChannelDownloader/Utilities/InlineProgress.cs diff --git a/YouTubeChannelDownloader/Utilities/InlineProgress.cs b/YouTubeChannelDownloader/Utilities/InlineProgress.cs new file mode 100644 index 0000000..8f38c53 --- /dev/null +++ b/YouTubeChannelDownloader/Utilities/InlineProgress.cs @@ -0,0 +1,35 @@ +using System; + +namespace YouTubeChannelDownloader.Utilities +{ + internal class InlineProgress : IProgress, 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 ✓"); + } + } +}