Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions ChangeLogs/2.0.0-ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# V2.0.0

## New Properties

| Property | Type | Default | Description |
|----------|------|---------|-------------|
| `Footers` | `string[]` | `Array.Empty<string>()` | The table footers. Footers are not required. |
| `FooterTextAlignmentRight` | `bool` | `false` | When `true`, footer text is right-aligned otherwise left aligned |

## New Method

| Method | Description |
|--------|-------------|
| `SetFooters(params string[] footers)` | Sets the table footers. Calling this again will overwrite previous footers. Footers are not required. |

## New Styling
- Headers now have a double bottom line to seperate them from the rows.
- Now an option to add footers to the table (optional). These are drawn without borders at the bottom.
- Footer text can be left or right aligned.

```csharp
using ConsoleTable.Text;

// Setup the table
var table = new Table();

// Set headers
table.SetHeaders("Name", "Age", "City");

// Add rows
table.AddRow("Alice Cooper", "30", "New York");

table.AddRows(new string[][]
{
new string[] { "Bob", "25", "Los Angeles" },
new string[] { "Charlie Brown", "47", "Chicago" }
});

//Set footers
table.SetFooters("Total: 3", "Total Age: 102");

// Display the table
Console.WriteLine(table.ToTable());
```

Output:
```
┌───────────────┬────────────────┬─────────────┐
│ Name │ Age │ City │
├═══════════════┼════════════════┼═════════════┤
│ Alice Cooper │ 30 │ New York │
├───────────────┼────────────────┼─────────────┤
│ Bob │ 25 │ Los Angeles │
├───────────────┼────────────────┼─────────────┤
│ Charlie Brown │ 47 │ Chicago │
└───────────────┴────────────────┴─────────────┘
Total: 3 Total Age: 102
```

## Performance Improvements
- Slightly improved performance when rendering large tables with many rows and columns.
73 changes: 64 additions & 9 deletions ConsoleTable.Text.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ static void Main(string[] args)

WriteDefaultTableWithProperties();

WriteTableWithStyling(true, true, 10);
WriteTableWithStyling(true, true, true, 10);

WriteTableWithStyling(false, true, 10);
WriteTableWithStyling(false, true, true, 10);

WriteTableWithStyling(true, false, 10);
WriteTableWithStyling(true, false, true, 10);

WriteTableWithStyling(false, false, 10);
WriteTableWithStyling(true, true, false, 10);

WriteTableWithoutHeaders();
WriteTableWithStyling(false, false, false, 10);

WriteTableOnlyHeaders();

WriteTableOnlyRows();

WriteTableOnlyFooters();

WriteTableMoreHeaders();

Expand All @@ -36,15 +42,24 @@ private static void WriteDefaultTable()
Console.WriteLine();
Console.WriteLine("Default table:");

// Setup the table
var table = new Table();

// Set headers
table.SetHeaders("Name", "Age", "City");

// Add rows
table.AddRow("Alice Cooper", "30", "New York");
table.AddRows(new string[][]
{
new string[] { "Bob", "25", "Los Angeles" },
new string[] { "Charlie Brown", "47", "Chicago" }
});

// Set footers
table.SetFooters("Total: 3", "Total Age: 102");

// Display the table
Console.WriteLine(table.ToTable());
Console.WriteLine();
}
Expand All @@ -70,15 +85,41 @@ private static void WriteDefaultTableWithProperties()
Console.WriteLine();
}

private static void WriteTableWithoutHeaders()
private static void WriteTableOnlyRows()
{
Console.WriteLine();
Console.WriteLine("Table without headers:");
Console.WriteLine("Table only rows:");

var table = new Table();

for (int i = 1; i <= 5; i++)
{
table.AddRow($"name {i}", (i * 15).ToString());
}

Console.WriteLine(table.ToString());
Console.WriteLine();
}

private static void WriteTableOnlyHeaders()
{
Console.WriteLine();
Console.WriteLine("Table only headers:");

var table = new Table();
table.SetHeaders("Name", "Age", "City");

Console.WriteLine(table.ToString());
Console.WriteLine();
}

private static void WriteTableOnlyFooters()
{
Console.WriteLine();
Console.WriteLine("Table only footers:");

var table = new Table();
table.SetFooters("Total: 3", "Total Age: 102");

Console.WriteLine(table.ToString());
Console.WriteLine();
Expand Down Expand Up @@ -145,24 +186,28 @@ private static void WriteTableEachRowRandom()
table.AddRow("Mathias", "37", "Oslo", "Norway", "Europe", "Earth", "Solar System");
table.AddRow("Kenny", "55", "Tokyo");

table.SetFooters("Footer 1", "Footer 2");

Console.WriteLine(table.ToString());
Console.WriteLine();
}

private static void WriteTableWithStyling(bool headerTextAlignRight, bool rowTextAlignRight, int padding)
private static void WriteTableWithStyling(bool headerTextAlignRight, bool rowTextAlignRight, bool footerTextAlignRight, int padding)
{
Console.WriteLine();
Console.WriteLine($"Table with following styling:");
Console.WriteLine($"Header text alignment: {(headerTextAlignRight ? "right" : "left")}");
Console.WriteLine($"Row text alignment: {(rowTextAlignRight ? "right" : "left")}");
Console.WriteLine($"Footer text alignment: {(footerTextAlignRight ? "right" : "left")}");
Console.WriteLine($"Padding: {padding}");

var table = new Table
{
CachingEnabled = true,
Padding = padding,
HeaderTextAlignmentRight = headerTextAlignRight,
RowTextAlignmentRight = rowTextAlignRight
RowTextAlignmentRight = rowTextAlignRight,
FooterTextAlignmentRight = footerTextAlignRight
};

table.SetHeaders("Name", "Age", "City");
Expand All @@ -175,6 +220,8 @@ private static void WriteTableWithStyling(bool headerTextAlignRight, bool rowTex
table.AddRow($"Very Long Name {i}", (i * 8).ToString(), $"City {i}");
}

table.SetFooters("Footer 1", "Footer 2", "Footer 3");

Console.WriteLine(table.ToString());
Console.WriteLine();
}
Expand All @@ -191,6 +238,7 @@ private static void WriteTableFluent()
new string[] { "Bob", "25", "Los Angeles" },
new string[] { "Charlie Brown", "47", "Chicago" }
)
.SetFooters("Total: 3", "Total Age: 102")
.ToTable();

Console.WriteLine(tableString);
Expand Down Expand Up @@ -230,6 +278,13 @@ private static void WriteBigTable()
}
table.Rows = rows;

var footers = new List<string>();
for (var columnPos = 1; columnPos <= columnCount; columnPos++)
{
footers.Add($"Footer {columnPos}");
}
table.Footers = footers.ToArray();

var tableString = table.ToTable();

Console.WriteLine(tableString);
Expand Down
6 changes: 3 additions & 3 deletions ConsoleTable.Text/ConsoleTable.Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

<!-- NuGet Package Metadata -->
<PackageId>ConsoleTable.Text</PackageId>
<Version>1.0.3</Version>
<Version>2.0.0</Version>
<Authors>Bruno Van Thournout</Authors>
<Description>A library for creating a formatted string tables with customizable headers, rows, and alignment options.</Description>
<Description>A library for creating a formatted string table with customizable headers, footers, rows and easy to use styling options.</Description>
<PackageProjectUrl>https://github.com/BrunoVT1992/ConsoleTable</PackageProjectUrl>
<RepositoryUrl>https://github.com/BrunoVT1992/ConsoleTable</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>console;table;formatting;cli</PackageTags>
<PackageTags>console;table;tables;consoletable;consoletables;console-table;texttable;text-table;output;format;formatting;cli;string;text;ct;fluent;grid</PackageTags>
<PackageLicenseExpression>MPL-2.0</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down
Loading