how to create console application in .net core

how to create console application in .net core

·

1 min read

Table of contents

Intro:-

Tables are used to display tabular data or text on terminal. Spectre.Console is a .NET library which is used to create console applications. Spectre.Console is rendering tables and adjust all columns to fit according to prompt. Table should implement IRenderable for column header or column cell, and another table!

Create Project
>dotnet new console -o cliapp

Install nuget package
>dotnet add package Spectre.Console

Create table object

var table = new Table();

without fluent

table.Centered();
 table.Collapse();
table.Border(TableBorder.HeavyHead);

or with fluent interface design pattern and method chaining

table.Centered().Collapse().Border(TableBorder.HeavyHead);

add columns

table.AddColumn("[magenta3]C[/]");
table.AddColumn(new TableColumn("[red3_1]C++[/]").Centered());

add rows

table.AddRow("[green]Java[/]", "[lightcyan1]D language[/]");
table.AddRow( new Panel("[deeppink2]C#[/]"));

Render table to prompt

AnsiConsole.Write(table);

Conclusion:-

To render a table, create a Table instance, add the number of columns according to app's requirement, and then add the rows. Complete the app by passing the table to a console's Write method.
Full source code is on github.