DevNation
DevNation

Follow

DevNation

Follow
How to create layout based terminal app in .net core

How to create layout based terminal app in .net core

DevNation's photo
DevNation
·Mar 3, 2023·

1 min read

Table of contents

  • Intro:-
  • Steps:-
  • Create Project:-
  • Install Nuget Package:-
  • Create Object:-
  • Split Columns:-
  • Split Rows:-
  • Set Ratio and Size:-
  • Set Visibility:-
  • Render the layout on Console:-
  • Conclusion:-

Intro:-

Layout class represents a renderable to divide a fixed height into rows or columns.Spectre.Console is a .NET library which is used to create console applications. Spectre.Console is rendering the tree on the terminal.

Steps:-

Create Project:-

>dotnet new console -o cliapplayout

Install Nuget Package:-

>dotnet add package Spectre.Console

Create Object:-

var layout = new Layout("Root")

Split Columns:-

new Layout("Left")

Split Rows:-

new Layout("Top Layout")

Set Ratio and Size:-

layout["Left"].Ratio(6); layout["Right"].Size(42);

Set Visibility:-

layout["Left"].Visible();

Render the layout on Console:-

AnsiConsole.Write(layout);

Conclusion:-

To create a layout, create object then split the Columns and Rows. Give Ratio and Size according to app requirement. Call Visible(), and Render the layout on Console. The full source code is on GitHub.

 
Share this