From f3451f5d414f8995cd4d69c6c9acb70e5bfadb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 7 Aug 2025 21:11:54 +0200 Subject: [PATCH] Lesson 4 Text prompts --- SpectreDemos/Program.cs | 55 ++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/SpectreDemos/Program.cs b/SpectreDemos/Program.cs index a06becd..e51525b 100644 --- a/SpectreDemos/Program.cs +++ b/SpectreDemos/Program.cs @@ -2,24 +2,49 @@ #region "Previous Lessons" //Lesson 2 - Initial Setup -//AnsiConsole.MarkupLine("[bold red]Hello, World![/]"); -//AnsiConsole.MarkupLine("Hello, World!"); -//AnsiConsole.MarkupLine("[slowblink]Hello, World![/]"); -#endregion +////AnsiConsole.MarkupLine("[bold red]Hello, World![/]"); +////AnsiConsole.MarkupLine("Hello, World!"); +////AnsiConsole.MarkupLine("[slowblink]Hello, World![/]"); + // Lesson 3 - Colors and styles -AnsiConsole.MarkupLine("[red]This is the inline markup[/]"); -AnsiConsole.MarkupLine("[red on white]This is the inline markup[/]"); -AnsiConsole.MarkupLine("[red on white bold]This is the inline markup[/]"); -Style danger = new Style( - foreground: Color.Red, - background: Color.White, - decoration: Decoration.Bold | Decoration.Italic - ); +////AnsiConsole.MarkupLine("[red]This is the inline markup[/]"); +////AnsiConsole.MarkupLine("[red on white]This is the inline markup[/]"); +////AnsiConsole.MarkupLine("[red on white bold]This is the inline markup[/]"); +////Style danger = new Style( +//// foreground: Color.Red, +//// background: Color.White, +//// decoration: Decoration.Bold | Decoration.Italic +//// ); -AnsiConsole.Write(new Markup("Danger Text from Style\n", danger)); -AnsiConsole.WriteLine(" and more..."); +////AnsiConsole.Write(new Markup("Danger Text from Style\n", danger)); +////AnsiConsole.WriteLine(" and more..."); +#endregion + + +// Lesson 4 - Text prompts + +//int age = AnsiConsole.Ask("What is your [green]age[/]?"); +int age = AnsiConsole.Prompt( + new TextPrompt("What is your age") + .Validate((x) => x switch + { + < 0 => ValidationResult.Error("You were not born yet!"), + > 120 => ValidationResult.Error("You are too old!"), + _ => ValidationResult.Success() + }) +); +//bool isHappy = AnsiConsole.Ask("Are you [green]happy[/]?"); + +string happyText = AnsiConsole.Prompt( + new TextPrompt("Are you [green]happy[/]?") + .AddChoice("Yes") + .AddChoice("No") + .DefaultValue("Yes") +); +AnsiConsole.MarkupLine($"Happy: {happyText}\nAge: {age}"); Console.ReadLine(); -AnsiConsole.Clear(); \ No newline at end of file +AnsiConsole.Clear(); +