Add examples of how to use Spectre.Console

This commit is contained in:
Patrik Svensson
2020-08-12 14:25:26 +02:00
parent 1d74fb909c
commit 0119364728
12 changed files with 445 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<Description>Demonstrates how to render items in panels.</Description>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
</ItemGroup>
</Project>

50
examples/Panel/Program.cs Normal file
View File

@@ -0,0 +1,50 @@
using System;
using Spectre.Console;
namespace PanelExample
{
class Program
{
static void Main(string[] args)
{
var content = Text.New(
"[underline]I[/] heard [underline on blue]you[/] like 📦\n\n\n\n" +
"So I put a 📦 in a 📦\n\n" +
"😅", foreground: Color.White);
AnsiConsole.Render(
new Panel(
new Panel(content)
{
Alignment = Justify.Center,
Border = BorderKind.Rounded
}));
// Left adjusted panel with text
AnsiConsole.Render(new Panel(
Text.New("Left adjusted\nLeft"))
{
Expand = true,
Alignment = Justify.Left,
});
// Centered ASCII panel with text
AnsiConsole.Render(new Panel(
Text.New("Centered\nCenter"))
{
Expand = true,
Alignment = Justify.Center,
Border = BorderKind.Ascii,
});
// Right adjusted, rounded panel with text
AnsiConsole.Render(new Panel(
Text.New("Right adjusted\nRight"))
{
Expand = true,
Alignment = Justify.Right,
Border = BorderKind.Rounded,
});
}
}
}