1
+ using System . Threading . Tasks ;
2
+
1
3
namespace Spectre . Console ;
2
4
3
5
/// <summary>
@@ -21,6 +23,23 @@ public static T Prompt<T>(IPrompt<T> prompt)
21
23
return prompt . Show ( Console ) ;
22
24
}
23
25
26
+ /// <summary>
27
+ /// Displays a prompt to the user.
28
+ /// </summary>
29
+ /// <typeparam name="T">The prompt result type.</typeparam>
30
+ /// <param name="prompt">The prompt to display.</param>
31
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
32
+ /// <returns>The prompt input result.</returns>
33
+ public static Task < T > PromptAsync < T > ( IPrompt < T > prompt , CancellationToken cancellationToken = default )
34
+ {
35
+ if ( prompt is null )
36
+ {
37
+ throw new ArgumentNullException ( nameof ( prompt ) ) ;
38
+ }
39
+
40
+ return prompt . ShowAsync ( Console , cancellationToken ) ;
41
+ }
42
+
24
43
/// <summary>
25
44
/// Displays a prompt to the user.
26
45
/// </summary>
@@ -32,6 +51,18 @@ public static T Ask<T>(string prompt)
32
51
return new TextPrompt < T > ( prompt ) . Show ( Console ) ;
33
52
}
34
53
54
+ /// <summary>
55
+ /// Displays a prompt to the user.
56
+ /// </summary>
57
+ /// <typeparam name="T">The prompt result type.</typeparam>
58
+ /// <param name="prompt">The prompt markup text.</param>
59
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
60
+ /// <returns>The prompt input result.</returns>
61
+ public static Task < T > AskAsync < T > ( string prompt , CancellationToken cancellationToken = default )
62
+ {
63
+ return new TextPrompt < T > ( prompt ) . ShowAsync ( Console , cancellationToken ) ;
64
+ }
65
+
35
66
/// <summary>
36
67
/// Displays a prompt to the user with a given default.
37
68
/// </summary>
@@ -46,6 +77,21 @@ public static T Ask<T>(string prompt, T defaultValue)
46
77
. Show ( Console ) ;
47
78
}
48
79
80
+ /// <summary>
81
+ /// Displays a prompt to the user with a given default.
82
+ /// </summary>
83
+ /// <typeparam name="T">The prompt result type.</typeparam>
84
+ /// <param name="prompt">The prompt markup text.</param>
85
+ /// <param name="defaultValue">The default value.</param>
86
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
87
+ /// <returns>The prompt input result.</returns>
88
+ public static Task < T > AskAsync < T > ( string prompt , T defaultValue , CancellationToken cancellationToken = default )
89
+ {
90
+ return new TextPrompt < T > ( prompt )
91
+ . DefaultValue ( defaultValue )
92
+ . ShowAsync ( Console , cancellationToken ) ;
93
+ }
94
+
49
95
/// <summary>
50
96
/// Displays a prompt with two choices, yes or no.
51
97
/// </summary>
@@ -60,4 +106,20 @@ public static bool Confirm(string prompt, bool defaultValue = true)
60
106
}
61
107
. Show ( Console ) ;
62
108
}
109
+
110
+ /// <summary>
111
+ /// Displays a prompt with two choices, yes or no.
112
+ /// </summary>
113
+ /// <param name="prompt">The prompt markup text.</param>
114
+ /// <param name="defaultValue">Specifies the default answer.</param>
115
+ /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
116
+ /// <returns><c>true</c> if the user selected "yes", otherwise <c>false</c>.</returns>
117
+ public static Task < bool > ConfirmAsync ( string prompt , bool defaultValue = true , CancellationToken cancellationToken = default )
118
+ {
119
+ return new ConfirmationPrompt ( prompt )
120
+ {
121
+ DefaultValue = defaultValue ,
122
+ }
123
+ . ShowAsync ( Console , cancellationToken ) ;
124
+ }
63
125
}
0 commit comments