spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Using the new and more precice `TimeProvider` for `ProgressTask` instead of `DateTime`

Open FaustVX opened this issue 1 month ago • 2 comments

Is your feature request related to a problem? Please describe. In my current project, I need to have a precise elapsed time column for my progress tasks, but they are all shown as 00:00:00 because there are too quick, and I need to see the ms also.

Describe the solution you'd like I've changed the ProgressTask.StartTime & ProgressTask.StopTime properties to long? then use the new API from .NET8: TimeProvider.System.GetTimestamp() & TimeProvider.System.GetElapsedTime()

Describe alternatives you've considered I didn't see any alternatives.

Additional context Before:

   Getting Infos ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00
   Getting input ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00
 Create Solution ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00
         Solving ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00
         Sending ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00

After:

   Getting Infos ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00.6375067
   Getting input ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00.5368024
 Create Solution ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00.0022177
         Solving ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00.5746945
         Sending ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00:00.0022711
await AnsiConsole.Progress()
    .Columns([
        new TaskDescriptionColumn(),
        new ProgressBarColumn(),
        new ElapsedTimeColumn() { Format = null }, // change the new Format property
    ]).StartAsync(...);

ElepsedTimeColumn.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);
}

I'm already using the modified version in my project flawlessly and am able to create the PR now. All the tests run fine.


Please upvote :+1: this issue if you are interested in it.

FaustVX avatar Nov 11 '25 14:11 FaustVX

@FaustVX Sure, send a PR

patriksvensson avatar Nov 11 '25 15:11 patriksvensson

Ok, PR sent

FaustVX avatar Nov 11 '25 15:11 FaustVX