TableFlex 2.0.0
dotnet add package TableFlex --version 2.0.0
NuGet\Install-Package TableFlex -Version 2.0.0
<PackageReference Include="TableFlex" Version="2.0.0" />
<PackageVersion Include="TableFlex" Version="2.0.0" />
<PackageReference Include="TableFlex" />
paket add TableFlex --version 2.0.0
#r "nuget: TableFlex, 2.0.0"
#:package TableFlex@2.0.0
#addin nuget:?package=TableFlex&version=2.0.0
#tool nuget:?package=TableFlex&version=2.0.0
TableFlex
<img src="docs/table-flex-logo.svg" alt="TableFlex Logo" width="256"/>
Description
TableFlex is a lightweight C# library for rendering console tables. It provides a simple way to align data into tables without manual formatting.
Installation
Install TableFlex via NuGet:
dotnet add package TableFlex
Or reference it directly in your .csproj:
<PackageReference Include="TableFlex" Version="2.0.0" />
Usage Example
Usings:
using TableFlex.Core;
using TableFlex.Renderers;
Example #1. Minimal usage:
Code:
Table table = new Table();
table.SetHeader("ID", "NAME", "AGE");
table.AddRow(1, "Alice", 9);
table.AddRow(2, "Benjamin", 69);
table.AddRow(3, "Bob", 27);
TableRenderer tr = new TableRenderer(BorderPresets.Dotted);
Console.WriteLine(tr.Render(table));
Output:
┌─────┬───────────┬──────┐
│ID │NAME │AGE │
├─────┼───────────┼──────┤
│1 │Alice │9 │
├─────┼───────────┼──────┤
│2 │Benjamin │69 │
├─────┼───────────┼──────┤
│3 │Bob │27 │
└─────┴───────────┴──────┘
Example #2. Advanced usage:
Code:
Table table = new Table();
table.SetHeader("ID", "NAME", "AGE");
table.AddRow(1, "Alice", 9);
table.AddRow(2, "Benjamin", 69);
table.AddRow(3, "Bob", 27);
BorderMap map = new BorderMap()
{
Horizontal = '-',
Cross = '-'
};
RenderOptions options = new RenderOptions()
{
Spacing = 5,
ShowOuterBorder = false,
ShowRowSeparators = false
};
TableRenderer tr = new TableRenderer(map, options);
Console.WriteLine(tr.Render(table));
Output:
ID NAME AGE
------------------------------
1 Alice 9
2 Benjamin 69
3 Bob 27
Components:
Table
Represents a table with optional header and rows.
Constructors:
Table()- Initializes a new empty table.
Methods:
SetHeader(params string[] headers)- Defines the header of the table.AddRow(params object[] contents)- Adds a new row to the table.
TableRenderer
Renders a table as plain text.
Constructors:
TableRenderer(BorderMap borderMap)- Initializes a new renderer with default options.TableRenderer(BorderMap borderMap, RenderOptions options)- Initializes a new renderer with custom options.
Methods:
Render(Table table)- Produces a string representation of the given table.
RenderOptions
Defines configurable options for rendering tables, including spacing, borders and separators.
Properties:
Spacing- Gets or sets the spacing between columns. Value can't be negative. (3by default)ShowOuterBorder- Indicates whether the outer border of the table should be rendered. (trueby default)ShowHeaderSeparator- Indicates whether a separator line should be rendered after the header. (trueby default)ShowColumnSeparators- Indicates whether vertical separators (vertical lines) between columns should be rendered. (trueby default)ShowRowSeparators- Indicates whether row separators (horizontal lines) should be rendered. (trueby default)
BorderMap
Defines the characters used to render table borders.
Constructors:
BorderMap()- Empty style with spaces.BorderMap(char symbol)- Single-symbol style with all characters equal.BorderMap(char horizontal, char vertical)- Horizontal-vertical style with distinct line characters.
Properties (' ' by default):
Horizontal- Horizontal line character used for table borders.Vertical- Vertical line character used for table borders.TopLeft- Top-left corner character.TopRight- Top-right corner character.BottomLeft- Bottom-left corner character.BottomRight- Bottom-right corner character.Cross- Intersection character used where horizontal and vertical lines cross.TopSeparator- Separator character used at intersections along the top border.BottomSeparator- Separator character used at intersections along the bottom border.LeftSeparator- Separator character used at intersections along the left border.RightSeparator- Separator character used at intersections along the right border.
BorderPresets
Provides predefined border styles for tables.
Properties:
Transparent- Border style without visible lines (all spaces).ID NAME AGE 1 Alice 9 2 Benjamin 69 3 Bob 27ASCII- Classic ASCII style using +, -, and |.+-----+-----------+------+ |ID |NAME |AGE | +-----+-----------+------+ |1 |Alice |9 | +-----+-----------+------+ |2 |Benjamin |69 | +-----+-----------+------+ |3 |Bob |27 | +-----+-----------+------+Unicode- Unicode single-line style with ┌, ─, ┐ and │.┌─────┬───────────┬──────┐ │ID │NAME │AGE │ ├─────┼───────────┼──────┤ │1 │Alice │9 │ ├─────┼───────────┼──────┤ │2 │Benjamin │69 │ ├─────┼───────────┼──────┤ │3 │Bob │27 │ └─────┴───────────┴──────┘DoubleLine- Double-line style with ╔, ═, ╗ and ║.╔═════╦═══════════╦══════╗ ║ID ║NAME ║AGE ║ ╠═════╬═══════════╬══════╣ ║1 ║Alice ║9 ║ ╠═════╬═══════════╬══════╣ ║2 ║Benjamin ║69 ║ ╠═════╬═══════════╬══════╣ ║3 ║Bob ║27 ║ ╚═════╩═══════════╩══════╝Dotted- Dotted style with . and :........................... :ID :NAME :AGE : :.....:...........:......: :1 :Alice :9 : :.....:...........:......: :2 :Benjamin :69 : :.....:...........:......: :3 :Bob :27 : :.....:...........:......:
Supports
- .NET 10.0
- .NET 8.0
License
TableFlex is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.