Tababular 4.3.0
dotnet add package Tababular --version 4.3.0
NuGet\Install-Package Tababular -Version 4.3.0
<PackageReference Include="Tababular" Version="4.3.0" />
paket add Tababular --version 4.3.0
#r "nuget: Tababular, 4.3.0"
// Install Tababular as a Cake Addin #addin nuget:?package=Tababular&version=4.3.0 // Install Tababular as a Cake Tool #tool nuget:?package=Tababular&version=4.3.0
Tababular
A simple .NET monospace text table formatting library for .NET 4.5 and .NET Standard 1.6.
You can use it if you are standing with a bunch of objects or dictionaries in your hand, and you wish for them to become as nice as this:
+-------------+--------------+-------------+
| FirstColumn | SecondColumn | ThirdColumn |
+-------------+--------------+-------------+
| r1 | hej | hej igen |
+-------------+--------------+-------------+
| r2 | hej | hej igen |
+-------------+--------------+-------------+
This can easily be achieved by newing up the TableFormatter
like this:
var formatter = new TableFormatter();
and then you call an appropriate Format***
method on it, e.g. FormatObjects
:
var objects = new[]
{
new {FirstColumn = "r1", SecondColumn = "hej", ThirdColumn = "hej igen"},
new {FirstColumn = "r2", SecondColumn = "hej", ThirdColumn = "hej igen"},
};
var text = tableFormatter.FormatObjects(objects);
Console.WriteLine(text);
which will result in the table shown above.
For now, Tababular does not support that much stuff - but one nice thing about it is that it will properly format lines in cells, so that e.g.
var objects = new[]
{
new { MachineName = "ctxtest01", Ip = "10.0.0.10", Ports = new[] {80, 8080, 9090}},
new { MachineName = "ctxtest02", Ip = "10.0.0.11", Ports = new[] {80, 5432}}
};
var text = new TableFormatter().FormatObjects(objects);
Console.WriteLine(text);
becomes nice like this:
+-----------+-------------+-------+
| Ip | MachineName | Ports |
+-----------+-------------+-------+
| 10.0.0.10 | ctxtest01 | 80 |
| | | 8080 |
| | | 9090 |
+-----------+-------------+-------+
| 10.0.0.11 | ctxtest02 | 80 |
| | | 5432 |
+-----------+-------------+-------+
which looks pretty neat if you ask me.
Formatting different things
Tababular can format different things, which at the moment includes:
- Objects:
formatter.FormatObjects(objects)
- Dictionaries:
formatter.FormatDictionaries(dictionaries)
- JSON:
formatter.FormatJson(jsonText)
More niceness
What about longs texts? Consider this example where the "Comments" column can be used to supply arbitrarily long texts:
var objects = new[]
{
new {MachineName = "ctxtest01", Ip = "10.0.0.10", Ports = new[] {80, 8080, 9090}, Comments = ""},
new {MachineName = "ctxtest02", Ip = "10.0.0.11", Ports = new[] {5432},
Comments = @"This bad boy hosts our database and a couple of internal jobs."}
};
var text = new TableFormatter().FormatObjects(objects);
In this case, the resulting table would look like this:
+----------------------------------------------------------------+-----------+-------------+-------+
| Comments | Ip | MachineName | Ports |
+----------------------------------------------------------------+-----------+-------------+-------+
| | 10.0.0.10 | ctxtest01 | 80 |
| | | | 8080 |
| | | | 9090 |
+----------------------------------------------------------------+-----------+-------------+-------+
| This bad boy hosts our database and a couple of internal jobs. | 10.0.0.11 | ctxtest02 | 5432 |
+----------------------------------------------------------------+-----------+-------------+-------+
which might be fine, but since the texts can be even longer than this, it might end up being a problem.
Fear not! We can supply a small hint to the table formatter like this:
var hints = new Hints { MaxTableWidth = 80 };
var formatter = new TableFormatter(hints);
and then when we
var text = formatter.FormatObjects(objects);
it will look like this:
+------------------------------------------------+-----------+-------------+-------+
| Comments | Ip | MachineName | Ports |
+------------------------------------------------+-----------+-------------+-------+
| | 10.0.0.10 | ctxtest01 | 80 |
| | | | 8080 |
| | | | 9090 |
+------------------------------------------------+-----------+-------------+-------+
| This bad boy hosts our database and a couple | 10.0.0.11 | ctxtest02 | 5432 |
| of internal jobs. | | | |
+------------------------------------------------+-----------+-------------+-------+
and the table will never become wider than at most 80 characters. Objectively speaking, this is actually freaking awesome.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- fastmember (>= 1.5.0)
- newtonsoft.json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Tababular:
Package | Downloads |
---|---|
Testy
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.3.0 | 960 | 8/21/2024 |
4.2.0 | 475 | 8/1/2024 |
4.1.0 | 174,870 | 12/28/2021 |
4.0.0 | 14,566 | 7/27/2020 |
3.0.1 | 30,180 | 2/20/2019 |
3.0.0 | 2,408 | 11/15/2018 |
3.0.0-b02 | 864 | 5/8/2018 |
3.0.0-b01 | 805 | 5/7/2018 |
2.0.0 | 2,385 | 7/28/2017 |
2.0.0-b01 | 846 | 4/26/2017 |
1.0.6 | 1,999 | 6/14/2016 |
1.0.5 | 1,120 | 2/23/2016 |
1.0.4 | 984 | 2/23/2016 |
1.0.3 | 1,008 | 2/21/2016 |
1.0.2 | 1,110 | 2/21/2016 |
1.0.1 | 1,032 | 2/20/2016 |
1.0.0 | 1,057 | 2/20/2016 |
1.0.0-a2 | 836 | 2/20/2016 |
1.0.0-a1 | 855 | 2/20/2016 |