ConsoleTablesPrinter 1.1.3

dotnet add package ConsoleTablesPrinter --version 1.1.3
                    
NuGet\Install-Package ConsoleTablesPrinter -Version 1.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConsoleTablesPrinter" Version="1.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConsoleTablesPrinter" Version="1.1.3" />
                    
Directory.Packages.props
<PackageReference Include="ConsoleTablesPrinter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConsoleTablesPrinter --version 1.1.3
                    
#r "nuget: ConsoleTablesPrinter, 1.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ConsoleTablesPrinter@1.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConsoleTablesPrinter&version=1.1.3
                    
Install as a Cake Addin
#tool nuget:?package=ConsoleTablesPrinter&version=1.1.3
                    
Install as a Cake Tool

NuGet

ConsoleTablesPrinter

A simple, flexible, and customizable table printer for .NET console applications.
Easily print objects and collections as styled console tables with minimal setup.


Features

  • Print single objects or lists as formatted console tables
  • Customizable table styles, borders, colors, padding, and "animations"
  • Support for property-level formatting and visibility using attributes
  • Multiple built-in border styles with UTF-8 or ASCII fallback
  • Supports cell text alignment and custom foreground/background colors
  • Easy to use extension methods for quick printing

Installation

Install via NuGet:

dotnet add package ConsoleTablePrinter --version 1.1.3

Or using the NuGet Package Manager:

Install-Package ConsoleTablePrinter -Version 1.1.3

Usage

using ConsoleTablesPrinter;
class Person
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public string? Email { get; set; }
    public DateOnly? DoB { get; set; }  
    public string? City { get; set; } 
}
class Program
{
    static void Main(string[] args)
    {
        var people = new List<Person>
        {
            new() { Id=1, Name = "Alice Johnson", Email="Alice@example.com", DoB = new DateOnly(1962,4,13), City = "Seattle" },
            new() { Id=2, Name = "Bob Smith", Email="bob@example.com", DoB =  new DateOnly(1991,7,27), City = "Portland" },
            new() { Id=3, Name = "Charlie Potato", Email="charlie.potato@example.com", DoB=  new DateOnly(1962,4,13), City = "San Francisco" }
        };
        people.PrintAsTable();
    }
}

screenshot

var person = new Person() { Id=1, Name = "Alice Johnson", Email="Alice@eample.com", DoB = new DateOnly(1962,4,13), City = "Seattle" };
person.PrintAsTable();

screenshot

When printing a single object, the table pivots into a 2-column layout showing property names and values.

Customize Table Style

You can customize the look and feel of your tables using the TableStyle class. Below are the available styling properties:

Specifies the print mode to use when rendering the table. Controls whether full styling is applied or a simplified Markdown format is produced.

Value Description
Normal Applies all styles, colors, and formatting attributes (default behavior).
Markdown Ignores all styles and attributes (except formatting and display name), producing a plain Markdown-compatible table output.
Examples

Normal Mode (default):

var style = new TableStyle
{
    PrintMode = TablePrintModes.Normal, // or omit this line completely
    // other styling options here
};

myList.PrintListAsTable(style);

Markdown Mode

people.PrintAsTable(o => o.PrintMode = TablePrintModes.Markdown); // OR
people.PrintAsTable(new TableStyle() { PrintMode = TablePrintModes.Markdown });

screenshot

var person = new Person() { Id = 1, Name = "Alice Johnson", Email = "Alice@eample.com", DoB = new DateOnly(1962, 4, 13), City = "Seattle" };
person.PrintAsTable(O => O.PrintMode = TablePrintModes.Markdown);

screenshot


Borders[^1]

Property Description
BorderStyle Sets the style of the outer table border. Defaults to SingleLine if null or unset. the available options are described below.
BorderColor The color used for the border lines, it uses the default System.ConsoleColor. Defaults to the console’s foreground color if null or unset.

Colors and Cell Styles[^1]

Property Description
BackgroundColor Background color applied to the entire table.
HeaderCellStyle Style settings for header cells (colors, alignment). Can be overridden per column using [TablePrintCol].
DataCellStyle Style settings for data cells. Can be overridden per column using [TablePrintCol].

Both HeaderCellStyle and DataCellStyle are of type CellStyle[^1]

Property Description
BackgroundColor Background color applied to the cell.
ForegroundColor Text (Foreground) color applied to the cell.
TextAlignment Text alignment [Left, Center, Right]. Defaults to left if null or unset

Padding & Spacing[^1]

Property Description
CellHorizontalPadding Number of spaces inside each cell (horizontal).
HorizontalPadding Spaces between the table and the left edge of the console.
VerticalPadding[^2] Blank lines above and below the table.

Row Layout[^1]

Property Description
UseRowSeparator If set to true it will add a line between each row for better readability.
RowSeparatorStyle (Optional) Use a different border style for row separators. Style of the row separators. Falls back to BorderStyle if not set. Only applies if UseRowSeparator is true.

"Animation"[^1]

Property Description
UseAnimation Enables a row-by-row reveal effect.
AnimationDelay Delay (in ms) between rows during animation. Clamped between 0 and 200.

Supported Border Styles[^1]

Property Uses the Characters
SingleLine ┌ ┐ └ ┘ ─ │ ┬ ┴ ┤ ├ ┼
SingleBoldLine ┏ ┓ ┗ ┛ ━ ┃ ┳ ┻ ┫ ┣ ╋
DoubleLine ╔ ╗ ╚ ╝ ═ ║ ╦ ╩ ╣ ╠ ╬
DoubleToSingleLine ╓ ╖ ╙ ╜ ─ ║ ╥ ╨ ╢ ╟ ╫
SingleToDoubleLine ╒ ╕ ╘ ╛ ═ │ ╤ ╧ ╡ ╞ ╪
SingleDashedLine ┌ ┐ └ ┘ ╌ ╎ ┬ ┴ ┤ ├ ┼
SingleDashedBoldLine ┏ ┓ ┗ ┛ ╍ ╏ ┳ ┻ ┫ ┣ ╋
SingleCurvedLine ╭ ╮ ╰ ╯ ─ │ ┬ ┴ ┤ ├ ┼
GoodOldAscii - |
ImprovedAscii + - |

Example Usage

Styles can be applied either inline via a lambda or by passing a pre-configured TableStyle object to PrintAsTable().

people.PrintAsTable(style =>
{
    style.BorderStyle = BorderStyles.SingleBoldLine;
    style.CellHorizontalPadding = 2;
    style.BackgroundColor = ConsoleColor.DarkBlue;
    style.BorderColor = ConsoleColor.Cyan;
    style.HeaderCellStyle = new CellStyle()
    {
        BackgroundColor = ConsoleColor.Cyan,
        ForegroundColor = ConsoleColor.DarkBlue,
        TextAlignment = TextAlignments.Center
    };
});

screenshot

Or

people.PrintAsTable(new TableStyle()
{
    BorderStyle = BorderStyles.SingleToDoubleLine,
    UseRowSeparator = true,
    RowSeparatorStyle = BorderStyles.SingleLine,
    BorderColor = ConsoleColor.Red,
    HorizontalPadding = 5,
    VerticalPadding = 1,
           
});

screenshot


Attributes for column customization

Use [TablePrintCol] attribute on your model properties to control how columns display. These will override other styling defined on the table that affect the property.

class Person
{
    public int Id { get; set; }
    [TablePrintCol(DisplayName = "Full Name")]
    public string? Name { get; set; }

    [TablePrintCol(Format = "C", CellTextAlignment = TextAlignments.Right, HeaderTextColor = ConsoleColor.Red, CellBgColor = ConsoleColor.DarkGray)]    
    public double Salary { get; set; }

    [TablePrintCol(Hidden = true)]
    public string? SecretCode { get; set; }
    
    public string? Email { get; set; }

    [TablePrintCol(DisplayName ="Date of Birth",Format = "MMM dd, yyyy",CellTextColor =ConsoleColor.Magenta)]
    public DateOnly? DoB { get; set; }
    public string? City { get; set; }
}

When printing a list of Person:

people.PrintAsTable(new TableStyle()
        {
            BorderStyle = BorderStyles.SingleToDoubleLine,
            UseRowSeparator = true,
            RowSeparatorStyle = BorderStyles.SingleLine,
            BorderColor = ConsoleColor.Red,
            HorizontalPadding = 5,
            VerticalPadding = 1,
            HeaderCellStyle = new CellStyle()
            {
                BackgroundColor = ConsoleColor.Yellow,
                ForegroundColor = ConsoleColor.Black,
            }
        });

screenshot

When printing a single Person object, styling is preserved and applied to the pivoted layout:

ConsoleTablePrinter.DefaultStyle = new TableStyle()
{
    BorderStyle = BorderStyles.SingleToDoubleLine,
    UseRowSeparator = true,
    RowSeparatorStyle = BorderStyles.SingleLine,
    BorderColor = ConsoleColor.Red,
    HorizontalPadding = 5,
    VerticalPadding = 1,
    HeaderCellStyle = new CellStyle()
    {
        BackgroundColor = ConsoleColor.Yellow,
        ForegroundColor = ConsoleColor.Black,
    }
};
var person = new Person() { Id = 1, Name = "Alice Johnson", Email = "Alice@eample.com", DoB = new DateOnly(1962, 4, 13), City = "Seattle" };
people.PrintAsTable();
person.PrintAsTable();

screenshot

Supported attributes:

The following attributes can be used on the model properties

Attribute Description
DisplayName The header text to display for the column. If not specified, the property name will be used as the header.
Format The format string used to format the column's values. This supports standard .NET format strings, e.g. "C2" for currency with two decimals.
Hidden Indicate whether this column should be hidden from the output.
HeaderBgColor[^1] The background color of the column header.
HeaderTextColor[^1] The text color of the column header.
HeaderTextAlignment[^1] The text alignment of the column header.
CellBgColor[^1] The background color of the cell content in this column.
CellTextColor[^1] The text color of the cell content in this column.
CellTextAlignment[^1] The text alignment of the cell content in this column.

TableStyle default

You can set a default style globally:

ConsoleTablePrinter.DefaultStyle = new TableStyle()
{
    BorderStyle = BorderStyles.SingleBoldLine,
    CellHorizontalPadding = 1,
    BackgroundColor = ConsoleColor.Black,
    BorderColor = ConsoleColor.Green,
};

If no style is specified in PrintAsTable(), this default will be used.

screenshot


Console Colors: ConsoleColor vs. ANSI Escape Codes

When printing styled tables, ConsoleTablePrinter supports both:

  • Standard .NET console coloring, using Console.ForegroundColor / Console.BackgroundColor.
  • Advanced coloring via ANSI escape sequences, like 256-color or 24-bit RGB.
Option 1: Using Console.ForegroundColor / Console.BackgroundColor

If you're setting the console color like this:

Console.ForegroundColor = ConsoleColor.White; // set the foreground
Console.BackgroundColor = ConsoleColor.Black; // Set background 
Console.Clear(); // Apply colors to the whole window by clearing the screen

You do not need to configure anything extra.

ConsoleTablePrinter automatically detects and restores these colors when rendering styled tables.

Option 2: Using ANSI Color Escape Sequences

If you're writing ANSI sequences directly, like:

string? ansifg = "\u001b[38;2;200;100;200m";
string? ansibg = "\u001b[48;2;130;30;30m";

Console.WriteLine(ansifg);  // set the foreground
Console.Write(ansibg);      // Set background 
Console.Write("\u001b[2J"); // Apply colors to the whole window by clearing the screen

Then the console doesn't track the current color state the way .NET APIs do.
So ConsoleTablePrinter won’t know how to reset your original colors after it's done printing.

To handle this properly, you must tell the printer what your default colors are:

ConsoleTablePrinter.ConsoleAnsiFg = ansifg;
ConsoleTablePrinter.ConsoleAnsiBg = ansibg;

This allows it to safely reset the console to your app's original appearance.


Summary: When You Need ConsoleAnsiFg / ConsoleAnsiBg

Scenario Required? Example
Using Console.ForegroundColor Console.ForegroundColor = ConsoleColor.Green;
Using ANSI 256-color \u001b[38;5;117m / \u001b[48;5;234m
Using ANSI RGB (True Color) \u001b[38;2;200;200;200m / \u001b[48;2;30;30;30m

If you're not sure whether you're using ANSI:

  • If you're manually writing \u001b[ codes, you're using ANSI.
  • If you're only setting ConsoleColor values, you're not.

If you need more information about ANSI Escape Sequences, you can take a look at this github resource


Version History

Version Last updated Desc
1.0.3 2025-06-03 Bug Fixes
1.0.4 2025-06-03 Read me updates
1.0.7 2025-06-03 Proj Health Flags
1.1.0 2025-06-05 Optimzation, Bug Fixes
1.1.3 2025-06-07 Added PrintingModes, Support for ANSI console fg/bg colors.

License

MIT License © Sam Farah


Contact

Feel free to open issues or contribute on GitHub.
GitHub Repository


Enjoy nicely formatted tables in your console apps!

[^1]: When PrintMode is set to TablePrintModes.Markdown, styling properties such as colors, borders, and cell styles are ignored, and output is simplified to plain Markdown format. [^2]: If VerticalPadding=0, there will be an extra line under the table but not above it. In Markdown mode it will behave as if it is set to 0

Product 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.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • 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.

Version Downloads Last Updated
1.1.3 118 6/7/2025
1.1.0 136 6/5/2025
1.0.7 154 6/4/2025