Adding TransferSpeedColumn configuration to display bits/bytes + binary/decimal prefixes (#904)

* Adding configuration to TransferSpeedColumn to be able to display in both bytes/bits, as well as using binary/decimal prefix definitions.

---------

Co-authored-by: Frank Ray <52075808+FrankRay78@users.noreply.github.com>
This commit is contained in:
Tim Pilius
2024-11-19 10:41:49 -05:00
committed by GitHub
parent 8d06daf355
commit aa9e5c48c6
9 changed files with 311 additions and 55 deletions

View File

@@ -10,10 +10,20 @@ public sealed class DownloadedColumn : ProgressColumn
/// </summary>
public CultureInfo? Culture { get; set; }
/// <summary>
/// Gets or sets the <see cref="FileSizeBase"/> to use.
/// </summary>
public FileSizeBase Base { get; set; } = FileSizeBase.Binary;
/// <summary>
/// Gets or sets a value indicating whether to display the transfer speed in bits.
/// </summary>
public bool ShowBits { get; set; }
/// <inheritdoc/>
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
var total = new FileSize(task.MaxValue);
var total = new FileSize(task.MaxValue, Base, ShowBits);
if (task.IsFinished)
{
@@ -24,7 +34,7 @@ public sealed class DownloadedColumn : ProgressColumn
}
else
{
var downloaded = new FileSize(task.Value, total.Unit);
var downloaded = new FileSize(task.Value, total.Prefix, Base, ShowBits);
return new Markup(string.Format(
"{0}[grey]/[/]{1} [grey]{2}[/]",

View File

@@ -10,6 +10,16 @@ public sealed class TransferSpeedColumn : ProgressColumn
/// </summary>
public CultureInfo? Culture { get; set; }
/// <summary>
/// Gets or sets the <see cref="FileSizeBase"/> to use.
/// </summary>
public FileSizeBase Base { get; set; } = FileSizeBase.Binary;
/// <summary>
/// Gets or sets a value indicating whether to display the transfer speed in bits.
/// </summary>
public bool ShowBits { get; set; }
/// <inheritdoc/>
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
@@ -18,7 +28,14 @@ public sealed class TransferSpeedColumn : ProgressColumn
return new Text("?/s");
}
var size = new FileSize(task.Speed.Value);
return new Markup(string.Format("{0}/s", size.ToString(suffix: true, Culture)));
if (task.IsFinished)
{
return new Markup(string.Empty, Style.Plain);
}
else
{
var size = new FileSize(task.Speed.Value, Base, ShowBits);
return new Markup(string.Format("{0}/s", size.ToString(suffix: true, Culture)));
}
}
}