Prompt
ConsoleMonster.Interactive
One-call prompts: Prompt.Select("Target", servers, s => s.Name), Prompt.Confirm("Continue?", true). For every option, build the prompt object (SelectPrompt<T>, TextPrompt, …) and call Show.
Inheritance
- object
- Prompt
Methods
public static bool Confirm(string title, bool? defaultValue = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks a yes/no question.
Parameters
- title string
- The question.
- defaultValue bool? = null
- The default answer, or null.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
bool The answer.public static Task<bool> ConfirmAsync(string title, bool? defaultValue = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks a yes/no question on a worker thread.
Parameters
- title string
- The question.
- defaultValue bool? = null
- The default answer, or null.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
Task<bool> The answer.public static int Integer(string title, int? defaultValue = null, int? minimum = null, int? maximum = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks for a whole number.
Parameters
- title string
- The question.
- defaultValue int? = null
- The default, or null.
- minimum int? = null
- The smallest value, or null.
- maximum int? = null
- The largest value, or null.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
int The number.public static IReadOnlyList<T?> MultiSelect<T>(string title, IEnumerable<T?> values, Func<T?, string>? display = null, Func<T?, string?>? group = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Picks any number of values.
Type Parameters
- T
- The value type.
Parameters
- title string
- The question.
- values System.Collections.Generic.IEnumerable<T?>
- The values.
- display System.Func<T?, string>? = null
- The title of a value; null uses its text.
- group System.Func<T?, string?>? = null
- The group of a value; null for none.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
IReadOnlyList<T?> The values in list order.public static decimal Number(string title, decimal? defaultValue = null, decimal? minimum = null, decimal? maximum = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks for a number.
Parameters
- title string
- The question.
- defaultValue decimal? = null
- The default, or null.
- minimum decimal? = null
- The smallest value, or null.
- maximum decimal? = null
- The largest value, or null.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
decimal The number.public static string Path(string title, PathKind kind = Any, bool mustExist = false, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks for a file or folder path.
Parameters
- title string
- The question.
- kind ConsoleMonster.Interactive.PathKind = Any
- What is accepted.
- mustExist bool = false
- Whether the path must exist.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
string The path as typed.public static string Secret(string title, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks for a secret (masked).
Parameters
- title string
- The question.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
string The secret.public static SecureString SecureSecret(string title, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks for a secret (masked) and returns it as a read-only SecureString (see SecretPrompt.ShowSecure).
Parameters
- title string
- The question.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
SecureString The secret.public static Task<T?> SelectAsync<T>(string title, IEnumerable<T?> values, Func<T?, string>? display = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Picks one value on a worker thread.
Type Parameters
- T
- The value type.
Parameters
- title string
- The question.
- values System.Collections.Generic.IEnumerable<T?>
- The values.
- display System.Func<T?, string>? = null
- The title of a value; null uses its text.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
Task<T?> The value.public static T? Select<T>(string title, IEnumerable<T?> values, Func<T?, string>? display = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Picks one value.
Type Parameters
- T
- The value type.
Parameters
- title string
- The question.
- values System.Collections.Generic.IEnumerable<T?>
- The values.
- display System.Func<T?, string>? = null
- The title of a value; null uses its text.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
T? The value.public static string Text(string title, string? defaultValue = null, Func<string, string?>? validator = null, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks for a line of text.
Parameters
- title string
- The question.
- defaultValue string? = null
- The default, or null.
- validator System.Func<string, string?>? = null
- Returns an error message, or null when the answer is fine.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
string The answer.public static bool TypedConfirm(string title, string expected, InteractiveOptions? options = null, CancellationToken cancellationToken = default) #Asks the user to type a text before a destructive action.
Parameters
- title string
- The question.
- expected string
- The text to type.
- options ConsoleMonster.Interactive.InteractiveOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the prompt.
Returns
bool True when confirmed.