Skip to content
ConsoleMonster
Class

Prompt

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Modifiers
static

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 required
The question.
defaultValue bool? = null optional
The default answer, or null.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
defaultValue bool? = null optional
The default answer, or null.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
defaultValue int? = null optional
The default, or null.
minimum int? = null optional
The smallest value, or null.
maximum int? = null optional
The largest value, or null.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
values System.Collections.Generic.IEnumerable<T?> required
The values.
display System.Func<T?, string>? = null optional
The title of a value; null uses its text.
group System.Func<T?, string?>? = null optional
The group of a value; null for none.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
defaultValue decimal? = null optional
The default, or null.
minimum decimal? = null optional
The smallest value, or null.
maximum decimal? = null optional
The largest value, or null.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
kind ConsoleMonster.Interactive.PathKind = Any optional
What is accepted.
mustExist bool = false optional
Whether the path must exist.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
values System.Collections.Generic.IEnumerable<T?> required
The values.
display System.Func<T?, string>? = null optional
The title of a value; null uses its text.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
values System.Collections.Generic.IEnumerable<T?> required
The values.
display System.Func<T?, string>? = null optional
The title of a value; null uses its text.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
defaultValue string? = null optional
The default, or null.
validator System.Func<string, string?>? = null optional
Returns an error message, or null when the answer is fine.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
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 required
The question.
expected string required
The text to type.
options ConsoleMonster.Interactive.InteractiveOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
Cancels the prompt.

Returns

bool True when confirmed.