From cceaa957358f45a28278d7f912cd08c09347a99b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Fri, 8 Aug 2025 09:49:14 +0200 Subject: [PATCH] Lesson 7 - Adding tables to your console --- SpectreDemos/Program.cs | 83 +++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 27 deletions(-) diff --git a/SpectreDemos/Program.cs b/SpectreDemos/Program.cs index 9c3a26d..530dde5 100644 --- a/SpectreDemos/Program.cs +++ b/SpectreDemos/Program.cs @@ -66,41 +66,70 @@ ////AnsiConsole.MarkupLine($"Your favorite name is: [bold red]{favoriteName}[/]."); -#endregion // Lesson 6 -List usualNames = [ - "Tim Corey", - "Sue Storm", - "Bilbo Baggins", - "John Doe", - "Princess Donaut", - "Steve Rogers" +////List usualNames = [ +//// "Tim Corey", +//// "Sue Storm", +//// "Bilbo Baggins", +//// "John Doe", +//// "Princess Donaut", +//// "Steve Rogers" +////]; + +////List familyNames = [ +//// "Charity", +//// "Jon", +//// "Chris" +////]; + +////List favoriteName = AnsiConsole.Prompt( +//// new MultiSelectionPrompt() +//// .Title("Which are your favorite placeholder names?") +//// .InstructionsText( +//// "[grey](Press [blue][/] to toggle selection, " + +//// "[green][/] to accept)[/]") +//// //.AddChoices(usualNames) +//// .AddChoiceGroup("Usual Names", usualNames) +//// .AddChoiceGroup("Family Names", familyNames) +////); + +////foreach (string name in favoriteName) +////{ +//// AnsiConsole.MarkupLine($"[bold red]{name}[/]"); +////} + +#endregion + +// Lesson 7 - Adding tables to your console + +List person = [ + new("Bilbo"), + new("Baggins"), + new("111") ]; -List familyNames = [ - "Charity", - "Jon", - "Chris" -]; +Table table = new Table(); +table.Centered(); +//table.Expand(); +//table.Border(TableBorder.Double); +table.Border(TableBorder.Rounded); +table.ShowRowSeparators(); -List favoriteName = AnsiConsole.Prompt( - new MultiSelectionPrompt() - .Title("Which are your favorite placeholder names?") - .InstructionsText( - "[grey](Press [blue][/] to toggle selection, " + - "[green][/] to accept)[/]") - //.AddChoices(usualNames) - .AddChoiceGroup("Usual Names", usualNames) - .AddChoiceGroup("Family Names", familyNames) -); +table.AddColumn("First Name"); +table.AddColumn("Last Name"); +table.AddColumn("Age"); -foreach (string name in favoriteName) -{ - AnsiConsole.MarkupLine($"[bold red]{name}[/]"); -} +table.Columns[0].PadLeft(5).PadRight(5); +table.Columns[1].Width(15); +table.Columns[2].RightAligned(); +table.AddRow("Tim", "Corey", "46"); +table.AddRow("Sue", "Storm", "23"); +table.AddRow(person); + +AnsiConsole.Write(table); Console.ReadLine(); AnsiConsole.Clear();