mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-09-15 09:05:33 +08:00
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:
@@ -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}[/]",
|
||||
|
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user