-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathProgram.cs
More file actions
108 lines (94 loc) · 3.53 KB
/
Copy pathProgram.cs
File metadata and controls
108 lines (94 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Text;
using System.Text.Json;
using Sharprompt.Example.Models;
namespace Sharprompt.Example;
// ReSharper disable LocalizableElement
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.UTF8;
while (true)
{
var type = Prompt.Select<ExampleType>("Choose prompt example");
switch (type)
{
case ExampleType.Input:
RunInputSample();
break;
case ExampleType.Confirm:
RunConfirmSample();
break;
case ExampleType.Password:
RunPasswordSample();
break;
case ExampleType.Select:
RunSelectSample();
break;
case ExampleType.MultiSelect:
RunMultiSelectSample();
break;
case ExampleType.SelectWithEnum:
RunSelectEnumSample();
break;
case ExampleType.MultiSelectWithEnum:
RunMultiSelectEnumSample();
break;
case ExampleType.List:
RunListSample();
break;
case ExampleType.Bind:
RunBindSample();
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
private static void RunInputSample()
{
var name = Prompt.Input<string>("What's your name?", defaultValue: "John Smith", placeholder: "At least 3 characters", validators: [Validators.Required(), Validators.MinLength(3)]);
Console.WriteLine($"Hello, {name}!");
}
private static void RunConfirmSample()
{
var answer = Prompt.Confirm("Are you ready?");
Console.WriteLine($"Your answer is {answer}");
}
private static void RunPasswordSample()
{
var secret = Prompt.Password("Type new password", placeholder: "At least 8 characters", validators: [Validators.Required(), Validators.MinLength(8)]);
Console.WriteLine($"Password OK, {secret}");
}
private static void RunSelectSample()
{
var city = Prompt.Select("Select your city", ["Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai"], pageSize: 3);
Console.WriteLine($"Hello, {city}!");
}
private static void RunMultiSelectSample()
{
var options = Prompt.MultiSelect("Which cities would you like to visit?", ["Seattle", "London", "Tokyo", "New York", "Singapore", "Shanghai"], pageSize: 3, defaultValues: ["Tokyo"]);
Console.WriteLine($"You picked {string.Join(", ", options)}");
}
private static void RunSelectEnumSample()
{
var value = Prompt.Select<MyEnum>("Select enum value", defaultValue: MyEnum.Bar);
Console.WriteLine($"You selected {value}");
}
private static void RunMultiSelectEnumSample()
{
var value = Prompt.MultiSelect<MyEnum>("Select enum value", defaultValues: [MyEnum.Bar]);
Console.WriteLine($"You picked {string.Join(", ", value)}");
}
private static void RunListSample()
{
var value = Prompt.List<string>("Please add item(s)");
Console.WriteLine($"You picked {string.Join(", ", value)}");
}
private static void RunBindSample()
{
var model = Prompt.Bind<MyFormModel>();
Console.WriteLine($"Forms OK, {JsonSerializer.Serialize(model)}");
}
}