spectre.console
spectre.console copied to clipboard
Using the new and more precice `TimeProvider` for `ProgressTask` instead of `DateTime`
fixes #1949
- [x] I have read the Contribution Guidelines
- [x] I have commented on the issue above and discussed the intended changes
- [x] A maintainer has signed off on the changes and the issue was assigned to me
- [x] All newly added code is adequately covered by tests
- [x] All existing tests are still running without errors
- [x] The documentation was modified to reflect the changes OR no documentation changes are required.
Changes
I've changed the ProgressTask.StartTime & ProgressTask.StopTime properties to long? then use the new API from .NET8: TimeProvider.System.GetTimestamp() & TimeProvider.System.GetElapsedTime()
I've also added Microsoft.Bcl.TimeProvider package for netstandard2.0 because TimeProvider is only available from net8.0
await AnsiConsole.Progress()
.Columns([
new TaskDescriptionColumn(),
new ProgressBarColumn(),
new ElapsedTimeColumn() { Format = null }, // change the new Format property
]).StartAsync(...);
ElepsedTimeColumn.cs & RemainingTimeColumn.cs
public string? Format { get; set; } = @"hh\:mm\:ss";
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
// ...
return new Text($"{elapsed.Value.ToString(Format)}", Style ?? Style.Plain);
}
Please upvote :+1: this pull request if you are interested in it.
@microsoft-github-policy-service agree