mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Docs redesign (#728)
* Adding a dark mode * Adding reference for types to summary pages * Adding API Reference * Adding modifiers to methods/fields/etc * Minimizing files input * Caching a lot of the output pages * Cache only for each execution * Adding API references to existing docs
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
namespace Spectre.Console.Examples
|
||||
using Spectre.Console;
|
||||
|
||||
namespace Prompt
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
@ -12,18 +14,28 @@ namespace Spectre.Console.Examples
|
||||
}
|
||||
|
||||
// Confirmation
|
||||
if (!AnsiConsole.Confirm("Run prompt example?"))
|
||||
if (!AskConfirmation())
|
||||
{
|
||||
AnsiConsole.MarkupLine("Ok... :(");
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask the user for some different things
|
||||
WriteDivider("Strings");
|
||||
var name = AskName();
|
||||
|
||||
WriteDivider("Lists");
|
||||
var fruit = AskFruit();
|
||||
|
||||
WriteDivider("Choices");
|
||||
var sport = AskSport();
|
||||
|
||||
WriteDivider("Integers");
|
||||
var age = AskAge();
|
||||
|
||||
WriteDivider("Secrets");
|
||||
var password = AskPassword();
|
||||
|
||||
WriteDivider("Optional");
|
||||
var color = AskColor();
|
||||
|
||||
// Summary
|
||||
@ -40,19 +52,31 @@ namespace Spectre.Console.Examples
|
||||
.AddRow("[grey]Favorite color[/]", string.IsNullOrEmpty(color) ? "Unknown" : color));
|
||||
}
|
||||
|
||||
private static string AskName()
|
||||
private static void WriteDivider(string text)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Rule("[yellow]Strings[/]").RuleStyle("grey").LeftAligned());
|
||||
AnsiConsole.Write(new Rule($"[yellow]{text}[/]").RuleStyle("grey").LeftAligned());
|
||||
}
|
||||
|
||||
public static bool AskConfirmation()
|
||||
{
|
||||
if (!AnsiConsole.Confirm("Run prompt example?"))
|
||||
{
|
||||
AnsiConsole.MarkupLine("Ok... :(");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string AskName()
|
||||
{
|
||||
var name = AnsiConsole.Ask<string>("What's your [green]name[/]?");
|
||||
return name;
|
||||
}
|
||||
|
||||
private static string AskFruit()
|
||||
public static string AskFruit()
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Rule("[yellow]Lists[/]").RuleStyle("grey").LeftAligned());
|
||||
|
||||
var favorites = AnsiConsole.Prompt(
|
||||
new MultiSelectionPrompt<string>()
|
||||
.PageSize(10)
|
||||
@ -87,11 +111,8 @@ namespace Spectre.Console.Examples
|
||||
return fruit;
|
||||
}
|
||||
|
||||
private static string AskSport()
|
||||
public static string AskSport()
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Rule("[yellow]Choices[/]").RuleStyle("grey").LeftAligned());
|
||||
|
||||
return AnsiConsole.Prompt(
|
||||
new TextPrompt<string>("What's your [green]favorite sport[/]?")
|
||||
.InvalidChoiceMessage("[red]That's not a sport![/]")
|
||||
@ -101,11 +122,8 @@ namespace Spectre.Console.Examples
|
||||
.AddChoice("Basketball"));
|
||||
}
|
||||
|
||||
private static int AskAge()
|
||||
public static int AskAge()
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Rule("[yellow]Integers[/]").RuleStyle("grey").LeftAligned());
|
||||
|
||||
return AnsiConsole.Prompt(
|
||||
new TextPrompt<int>("How [green]old[/] are you?")
|
||||
.PromptStyle("green")
|
||||
@ -121,22 +139,16 @@ namespace Spectre.Console.Examples
|
||||
}));
|
||||
}
|
||||
|
||||
private static string AskPassword()
|
||||
public static string AskPassword()
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Rule("[yellow]Secrets[/]").RuleStyle("grey").LeftAligned());
|
||||
|
||||
return AnsiConsole.Prompt(
|
||||
new TextPrompt<string>("Enter [green]password[/]?")
|
||||
.PromptStyle("red")
|
||||
.Secret());
|
||||
}
|
||||
|
||||
private static string AskColor()
|
||||
public static string AskColor()
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Write(new Rule("[yellow]Optional[/]").RuleStyle("grey").LeftAligned());
|
||||
|
||||
return AnsiConsole.Prompt(
|
||||
new TextPrompt<string>("[grey][[Optional]][/] What is your [green]favorite color[/]?")
|
||||
.AllowEmpty());
|
||||
|
Reference in New Issue
Block a user