diff --git a/CliFx.Tests/Utilities/ProgressReporterTests.cs b/CliFx.Tests/Utilities/ProgressTickerTests.cs similarity index 84% rename from CliFx.Tests/Utilities/ProgressReporterTests.cs rename to CliFx.Tests/Utilities/ProgressTickerTests.cs index 3882d36..74a4efb 100644 --- a/CliFx.Tests/Utilities/ProgressReporterTests.cs +++ b/CliFx.Tests/Utilities/ProgressTickerTests.cs @@ -9,7 +9,7 @@ using NUnit.Framework; namespace CliFx.Tests.Utilities { [TestFixture] - public class ProgressReporterTests + public class ProgressTickerTests { [Test] public void Report_Test() @@ -20,14 +20,14 @@ namespace CliFx.Tests.Utilities using (var stdout = new StringWriter(formatProvider)) { var console = new VirtualConsole(TextReader.Null, false, stdout, false, TextWriter.Null, false); - var reporter = console.CreateProgressReporter(); + var ticker = console.CreateProgressTicker(); var progressValues = Enumerable.Range(0, 100).Select(p => p / 100.0).ToArray(); var progressStringValues = progressValues.Select(p => p.ToString("P2", formatProvider)).ToArray(); // Act foreach (var progress in progressValues) - reporter.Report(progress); + ticker.Report(progress); // Assert stdout.ToString().Should().ContainAll(progressStringValues); @@ -41,13 +41,13 @@ namespace CliFx.Tests.Utilities using (var stdout = new StringWriter()) { var console = new VirtualConsole(stdout); - var reporter = console.CreateProgressReporter(); + var ticker = console.CreateProgressTicker(); var progressValues = Enumerable.Range(0, 100).Select(p => p / 100.0).ToArray(); // Act foreach (var progress in progressValues) - reporter.Report(progress); + ticker.Report(progress); // Assert stdout.ToString().Should().BeEmpty(); diff --git a/CliFx/Utilities/Extensions.cs b/CliFx/Utilities/Extensions.cs index 3cd7e0d..abd8c38 100644 --- a/CliFx/Utilities/Extensions.cs +++ b/CliFx/Utilities/Extensions.cs @@ -8,8 +8,8 @@ namespace CliFx.Utilities public static class Extensions { /// - /// Creates a progress reporter for this console. + /// Creates a bound to this console. /// - public static ProgressReporter CreateProgressReporter(this IConsole console) => new ProgressReporter(console); + public static ProgressTicker CreateProgressTicker(this IConsole console) => new ProgressTicker(console); } } \ No newline at end of file diff --git a/CliFx/Utilities/ProgressReporter.cs b/CliFx/Utilities/ProgressTicker.cs similarity index 77% rename from CliFx/Utilities/ProgressReporter.cs rename to CliFx/Utilities/ProgressTicker.cs index 6a660a8..d0e1651 100644 --- a/CliFx/Utilities/ProgressReporter.cs +++ b/CliFx/Utilities/ProgressTicker.cs @@ -4,18 +4,18 @@ using CliFx.Services; namespace CliFx.Utilities { /// - /// Utility that provides continuous progress reporting to the console. + /// Utility for rendering current progress to the console that erases and rewrites output on every tick. /// - public class ProgressReporter : IProgress + public class ProgressTicker : IProgress { private readonly IConsole _console; private string _lastOutput = ""; /// - /// Initializes an instance of . + /// Initializes an instance of . /// - public ProgressReporter(IConsole console) + public ProgressTicker(IConsole console) { _console = console; } @@ -33,7 +33,7 @@ namespace CliFx.Utilities } /// - /// Reports progress and renders it to console. + /// Erases previous output and renders new progress to the console. /// If console's stdout is redirected, this method returns without doing anything. /// public void Report(double progress) diff --git a/Readme.md b/Readme.md index bb8c12d..7344856 100644 --- a/Readme.md +++ b/Readme.md @@ -265,15 +265,17 @@ var app = new CliApplicationBuilder() ### Report progress -CliFx comes with a simple utility for rendering progress to the console, `ProgressReporter`. It implements a well-known `IProgress` interface so you can pass it to methods that are aware of this abstraction. +CliFx comes with a simple utility for reporting progress to the console, `ProgressTicker`, which renders progress in-place on every tick. -To avoid polluting output when it's not bound to a console, `ProgressReporter` will simply no-op if stdout is redirected. +It implements a well-known `IProgress` interface so you can pass it to methods that are aware of this abstraction. + +To avoid polluting output when it's not bound to a console, `ProgressTicker` will simply no-op if stdout is redirected. ```c# -var progressReporter = console.CreateProgressReporter(); +var progressTicker = console.CreateProgressTicker(); for (var i = 0.0; i <= 1; i += 0.01) - progressReporter.Report(i); + progressTicker.Report(i); ``` ### Testing