Lesson 7 - Adding tables to your console

This commit is contained in:
2025-08-08 09:49:14 +02:00
parent 5d40f95829
commit cceaa95735

View File

@ -66,41 +66,70 @@
////AnsiConsole.MarkupLine($"Your favorite name is: [bold red]{favoriteName}[/].");
#endregion
// Lesson 6
List<string> usualNames = [
"Tim Corey",
"Sue Storm",
"Bilbo Baggins",
"John Doe",
"Princess Donaut",
"Steve Rogers"
////List<string> usualNames = [
//// "Tim Corey",
//// "Sue Storm",
//// "Bilbo Baggins",
//// "John Doe",
//// "Princess Donaut",
//// "Steve Rogers"
////];
////List<string> familyNames = [
//// "Charity",
//// "Jon",
//// "Chris"
////];
////List<string> favoriteName = AnsiConsole.Prompt(
//// new MultiSelectionPrompt<string>()
//// .Title("Which are your favorite placeholder names?")
//// .InstructionsText(
//// "[grey](Press [blue]<space>[/] to toggle selection, " +
//// "[green]<enter>[/] 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<Text> person = [
new("Bilbo"),
new("Baggins"),
new("111")
];
List<string> familyNames = [
"Charity",
"Jon",
"Chris"
];
Table table = new Table();
table.Centered();
//table.Expand();
//table.Border(TableBorder.Double);
table.Border(TableBorder.Rounded);
table.ShowRowSeparators();
List<string> favoriteName = AnsiConsole.Prompt(
new MultiSelectionPrompt<string>()
.Title("Which are your favorite placeholder names?")
.InstructionsText(
"[grey](Press [blue]<space>[/] to toggle selection, " +
"[green]<enter>[/] 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();