Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.Bcl.TimeProvider" Version="10.0.0" />
<PackageVersion Include="AngleSharp" Version="1.4.0" />
<PackageVersion Include="Humanizer.Core" Version="2.14.1" />
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
Expand All @@ -28,4 +29,4 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
</ItemGroup>
</Project>
</Project>
22 changes: 10 additions & 12 deletions src/Spectre.Console/Live/Progress/Columns/ElapsedTimeColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ public sealed class ElapsedTimeColumn : ProgressColumn
protected internal override bool NoWrap => true;

/// <summary>
/// Gets or sets the style of the remaining time text.
/// Gets or sets the style of the elapsed time text.
/// </summary>
public Style Style { get; set; } = Color.Blue;

/// <summary>
/// Gets or sets the format of the elapsed time text.
/// </summary>
public string? Format { get; set; } = @"hh\:mm\:ss";

/// <inheritdoc/>
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
var elapsed = task.ElapsedTime;
if (elapsed == null)
if (task.ElapsedTime is not TimeSpan elapsed)
{
return new Markup("--:--:--");
}

if (elapsed.Value.TotalHours > 99)
if (elapsed.TotalHours > 99)
{
return new Markup("**:**:**");
}

return new Text($"{elapsed.Value:hh\\:mm\\:ss}", Style ?? Style.Plain);
}

/// <inheritdoc/>
public override int? GetColumnWidth(RenderOptions options)
{
return 8;
return new Text($"{elapsed.ToString(Format)}", Style ?? Style.Plain);
}
}
}
20 changes: 9 additions & 11 deletions src/Spectre.Console/Live/Progress/Columns/RemainingTimeColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@ public sealed class RemainingTimeColumn : ProgressColumn
/// </summary>
public Style Style { get; set; } = Color.Blue;

/// <summary>
/// Gets or sets the format of the remaining time text.
/// </summary>
public string? Format { get; set; } = @"hh\:mm\:ss";

/// <inheritdoc/>
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
var remaining = task.RemainingTime;
if (remaining == null)
if (task.RemainingTime is not TimeSpan remaining)
{
return new Markup("--:--:--");
}

if (remaining.Value.TotalHours > 99)
if (remaining.TotalHours > 99)
{
return new Markup("**:**:**");
}

return new Text($"{remaining.Value:hh\\:mm\\:ss}", Style ?? Style.Plain);
}

/// <inheritdoc/>
public override int? GetColumnWidth(RenderOptions options)
{
return 8;
return new Text($"{remaining.ToString(Format)}", Style ?? Style.Plain);
}
}
}
20 changes: 10 additions & 10 deletions src/Spectre.Console/Live/Progress/ProgressTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public double Value
/// <summary>
/// Gets the start time of the task.
/// </summary>
public DateTime? StartTime { get; private set; }
public long? StartTime { get; private set; }

/// <summary>
/// Gets the stop time of the task.
/// </summary>
public DateTime? StopTime { get; private set; }
public long? StopTime { get; private set; }

/// <summary>
/// Gets the task state.
Expand Down Expand Up @@ -118,7 +118,7 @@ public ProgressTask(int id, string description, double maxValue, bool autoStart

Id = id;
State = new ProgressTaskState();
StartTime = autoStart ? DateTime.Now : null;
StartTime = autoStart ? TimeProvider.System.GetTimestamp() : null;
}

/// <summary>
Expand All @@ -133,7 +133,7 @@ public void StartTask()
throw new InvalidOperationException("Stopped tasks cannot be restarted");
}

StartTime = DateTime.Now;
StartTime = TimeProvider.System.GetTimestamp();
StopTime = null;
}
}
Expand All @@ -145,7 +145,7 @@ public void StopTask()
{
lock (_lock)
{
var now = DateTime.Now;
var now = TimeProvider.System.GetTimestamp();
StartTime ??= now;

StopTime = now;
Expand Down Expand Up @@ -263,17 +263,17 @@ private double GetPercentage()
{
lock (_lock)
{
if (StartTime == null)
if (StartTime is not long start)
{
return null;
}

if (StopTime != null)
if (StopTime is long stop)
{
return StopTime - StartTime;
return TimeProvider.System.GetElapsedTime(start, stop);
}

return DateTime.Now - StartTime;
return TimeProvider.System.GetElapsedTime(start);
}
}

Expand Down Expand Up @@ -310,4 +310,4 @@ void IProgress<double>.Report(double value)
{
Update(increment: value - Value);
}
}
}
1 change: 1 addition & 0 deletions src/Spectre.Console/Spectre.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.TimeProvider" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="Wcwidth.Sources" PrivateAssets="all" />
<PackageReference Include="System.Memory" Condition="'$(TargetFramework)' == 'netstandard2.0'"/>
<PackageReference Include="Polyfill" Condition="'$(TargetFramework)' == 'netstandard2.0'" PrivateAssets="all" />
Expand Down