mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add tree example
This commit is contained in:

committed by
Patrik Svensson

parent
1aa958ced3
commit
87e6b42409
47
examples/Console/Trees/Program.cs
Normal file
47
examples/Console/Trees/Program.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace TableExample
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var tree = new Tree();
|
||||
|
||||
tree.AddNode(new FigletText("Dec 2020"));
|
||||
tree.AddNode(new Markup("[link]Click to go to summary[/]"));
|
||||
|
||||
// Add the calendar nodes
|
||||
tree.AddNode(new Markup("[blue]Calendar[/]"),
|
||||
node => node.AddNode(
|
||||
new Calendar(2020, 12)
|
||||
.AddCalendarEvent(2020, 12, 12)
|
||||
.HideHeader()));
|
||||
|
||||
// Add video games node
|
||||
tree.AddNode(new Markup("[red]Played video games[/]"),
|
||||
node => node.AddNode(
|
||||
new Table()
|
||||
.RoundedBorder()
|
||||
.AddColumn("Title")
|
||||
.AddColumn("Console")
|
||||
.AddRow("The Witcher 3", "XBox One X")
|
||||
.AddRow("Cyberpunk 2077", "PC")
|
||||
.AddRow("Animal Crossing", "Nintendo Switch")));
|
||||
|
||||
|
||||
// Add the fruit nodes
|
||||
tree.AddNode(new Markup("[green]Fruits[/]"), fruits =>
|
||||
fruits.AddNode(new Markup("Eaten"),
|
||||
node => node.AddNode(
|
||||
new BarChart().Width(40)
|
||||
.AddItem("Apple", 12, Color.Red)
|
||||
.AddItem("Kiwi", 3, Color.Green)
|
||||
.AddItem("Banana", 21, Color.Yellow))));
|
||||
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.MarkupLine("[yellow]Monthly summary[/]");
|
||||
AnsiConsole.Render(tree);
|
||||
}
|
||||
}
|
||||
}
|
15
examples/Console/Trees/Trees.csproj
Normal file
15
examples/Console/Trees/Trees.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<ExampleTitle>Trees</ExampleTitle>
|
||||
<ExampleDescription>Demonstrates how to render trees in a console.</ExampleDescription>
|
||||
<ExampleGroup>Widgets</ExampleGroup>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user