-
-
Notifications
You must be signed in to change notification settings - Fork 600
Adding TransferSpeedColumn configuration to display bits/bytes + binary/decimal prefixes #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
FrankRay78
merged 5 commits into
spectreconsole:main
from
tpill90:feature/TransferSpeedColumnConfigurePrefix
Nov 19, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9181f9b
Adding configuration to TransferSpeedColumn to be able to display in …
tpill90 dbb9074
PR changes
tpill90 cf57c51
Moving test into the new correct location
tpill90 4087a31
Unit tests
tpill90 b60eeac
Update documentation; Stop showing transfer speed once complete; Mino…
FrankRay78 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Spectre.Console; | ||
|
||
/// <summary> | ||
/// Determines possible file size base prefixes. (base 2/base 10). | ||
/// </summary> | ||
public enum FileSizeBase | ||
{ | ||
/// <summary> | ||
/// The SI prefix definition (base 10) of kilobyte, megabyte, etc. | ||
/// </summary> | ||
Decimal = 1000, | ||
|
||
/// <summary> | ||
/// The IEC binary prefix definition (base 2) of kibibyte, mebibyte, etc. | ||
/// </summary> | ||
Binary = 1024, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Spectre.Console; | ||
|
||
internal enum FileSizePrefix | ||
{ | ||
None = 0, | ||
Kilo = 1, | ||
Mega = 2, | ||
Giga = 3, | ||
Tera = 4, | ||
Peta = 5, | ||
Exa = 6, | ||
Zetta = 7, | ||
Yotta = 8, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/Tests/Spectre.Console.Tests/Unit/Internal/FileSizeTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
namespace Spectre.Console.Tests.Unit.Internal; | ||
|
||
public sealed class FileSizeTests | ||
{ | ||
[Theory] | ||
[InlineData(0, "0 bytes")] | ||
[InlineData(37, "37 bytes")] | ||
[InlineData(512, "512 bytes")] | ||
[InlineData(15 * 1024, "15.0 KiB")] | ||
[InlineData(1024 * 512, "512.0 KiB")] | ||
[InlineData(5 * 1024 * 1024, "5.0 MiB")] | ||
[InlineData(9 * 1024 * 1024, "9.0 MiB")] | ||
public void Binary_Unit_In_Bytes_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Binary); | ||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "0 bits")] | ||
[InlineData(37, "296 bits")] | ||
[InlineData(512, "4.0 Kibit")] | ||
[InlineData(15 * 1024, "120.0 Kibit")] | ||
[InlineData(1024 * 512, "4.0 Mibit")] | ||
[InlineData(5 * 1024 * 1024, "40.0 Mibit")] | ||
[InlineData(210 * 1024 * 1024, "1.6 Gibit")] | ||
[InlineData(900 * 1024 * 1024, "7.0 Gibit")] | ||
public void Binary_Unit_In_Bits_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Binary, showBits: true); | ||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "0 bytes")] | ||
[InlineData(37, "37 bytes")] | ||
[InlineData(512, "512 bytes")] | ||
[InlineData(15 * 1024, "15.4 KB")] | ||
[InlineData(1024 * 512, "524.3 KB")] | ||
[InlineData(5 * 1024 * 1024, "5.2 MB")] | ||
[InlineData(9 * 1024 * 1024, "9.4 MB")] | ||
public void Decimal_Unit_In_Bytes_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Decimal); | ||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
|
||
[Theory] | ||
[InlineData(0, "0 bits")] | ||
[InlineData(37, "296 bits")] | ||
[InlineData(512, "4.1 Kbit")] | ||
[InlineData(15 * 1024, "122.9 Kbit")] | ||
[InlineData(1024 * 512, "4.2 Mbit")] | ||
[InlineData(5 * 1024 * 1024, "41.9 Mbit")] | ||
[InlineData(900 * 1024 * 1024, "7.5 Gbit")] | ||
public void Decimal_Unit_In_Bits_Should_Return_Expected(double bytes, string expected) | ||
{ | ||
// Given | ||
var filesize = new FileSize(bytes, FileSizeBase.Decimal, showBits: true); | ||
|
||
// When | ||
var result = filesize.ToString(); | ||
|
||
// Then | ||
result.ShouldBe(expected); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.