Integrating with ConsoleTables - Tyrrrz/CliFx GitHub Wiki

ConsoleTables is a utility library for rendering tables via console output.

To integrate it with CliFx:

  1. Install ConsoleTables NuGet package

  2. Create an instance of ConsoleTable bound to the console instance provided by CliFx command:

[Command]
public class TestCommand : ICommand
{
    public ValueTask ExecuteAsync(IConsole console)
    {
        var table = new ConsoleTable(new ConsoleTableOptions
        {
            OutputTo = console.Output
        });

        table
         .AddRow(1, 2, 3)
         .AddRow("foo", "bar", "baz");

        table.Write();

        // ...
    }
}

Alternatively, use the fluent API and call the Configure() method:

[Command]
public class TestCommand : ICommand
{
    public ValueTask ExecuteAsync(IConsole console)
    {
        var rows = Enumerable.Repeat(new Something(), 10);

        ConsoleTable
            .From<Something>(rows)
            .Configure(o => o.OutputTo = console.Output)
            .Write();

        // ...
    }
}
⚠️ **GitHub.com Fallback** ⚠️