Lesson 4 Text prompts
This commit is contained in:
@ -2,24 +2,49 @@
|
|||||||
|
|
||||||
#region "Previous Lessons"
|
#region "Previous Lessons"
|
||||||
//Lesson 2 - Initial Setup
|
//Lesson 2 - Initial Setup
|
||||||
//AnsiConsole.MarkupLine("[bold red]Hello, World![/]");
|
////AnsiConsole.MarkupLine("[bold red]Hello, World![/]");
|
||||||
//AnsiConsole.MarkupLine("Hello, World!");
|
////AnsiConsole.MarkupLine("Hello, World!");
|
||||||
//AnsiConsole.MarkupLine("[slowblink]Hello, World![/]");
|
////AnsiConsole.MarkupLine("[slowblink]Hello, World![/]");
|
||||||
#endregion
|
|
||||||
|
|
||||||
// Lesson 3 - Colors and styles
|
// Lesson 3 - Colors and styles
|
||||||
|
|
||||||
AnsiConsole.MarkupLine("[red]This is the inline markup[/]");
|
////AnsiConsole.MarkupLine("[red]This is the inline markup[/]");
|
||||||
AnsiConsole.MarkupLine("[red on white]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[/]");
|
////AnsiConsole.MarkupLine("[red on white bold]This is the inline markup[/]");
|
||||||
Style danger = new Style(
|
////Style danger = new Style(
|
||||||
foreground: Color.Red,
|
//// foreground: Color.Red,
|
||||||
background: Color.White,
|
//// background: Color.White,
|
||||||
decoration: Decoration.Bold | Decoration.Italic
|
//// decoration: Decoration.Bold | Decoration.Italic
|
||||||
);
|
//// );
|
||||||
|
|
||||||
AnsiConsole.Write(new Markup("Danger Text from Style\n", danger));
|
////AnsiConsole.Write(new Markup("Danger Text from Style\n", danger));
|
||||||
AnsiConsole.WriteLine(" and more...");
|
////AnsiConsole.WriteLine(" and more...");
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
// Lesson 4 - Text prompts
|
||||||
|
|
||||||
|
//int age = AnsiConsole.Ask<int>("What is your [green]age[/]?");
|
||||||
|
int age = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<int>("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<bool>("Are you [green]happy[/]?");
|
||||||
|
|
||||||
|
string happyText = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("Are you [green]happy[/]?")
|
||||||
|
.AddChoice("Yes")
|
||||||
|
.AddChoice("No")
|
||||||
|
.DefaultValue("Yes")
|
||||||
|
);
|
||||||
|
AnsiConsole.MarkupLine($"Happy: {happyText}\nAge: {age}");
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
AnsiConsole.Clear();
|
AnsiConsole.Clear();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user