TextPrompt<>

Represents a prompt.

Represents a prompt.

Constructors

public TextPrompt`1(string prompt, StringComparer comparer = null)

Initializes a new instance of the TextPrompt class.

Parameters:

prompt (string)
The prompt markup text.
comparer (StringComparer)
The comparer used for choices.

Properties

AllowEmpty : bool

Gets or sets a value indicating whether or not an empty result is valid.

Choices : List<T>

Gets the list of choices.

ClearOnFinish : bool

Gets or sets a value indicating whether the prompt line should be cleared after a successful input.

Converter : Func<T, string>

Gets or sets the converter to get the display string for a choice. By default the corresponding TypeConverter is used.

Culture : CultureInfo

Gets or sets the culture to use when converting input to object.

EditableDefaultValue : bool

Gets or sets the default value editable state that allows the injection of the DefaultValue in the text field. If true this places the DefaultValue in the input buffer which can then be edited by the user.

InvalidChoiceMessage : string

Gets or sets the message for invalid choices.

IsSecret : bool

Gets or sets a value indicating whether input should be hidden in the console.

Mask : char?

Gets or sets the character to use while masking a secret prompt.

ShowChoices : bool

Gets or sets a value indicating whether or not choices should be shown.

ShowDefaultValue : bool

Gets or sets a value indicating whether or not default values should be shown.

ValidationErrorMessage : string

Gets or sets the validation error message.

Validator : Func<T, ValidationResult>

Gets or sets the validator.

Methods

public T Show(IAnsiConsole console)

Shows the prompt and requests input from the user.

Parameters:

console (IAnsiConsole)
The console to show the prompt in.

Returns:

The user input converted to the expected type.

public Task<T> ShowAsync(IAnsiConsole console, CancellationToken cancellationToken)

Shows the prompt asynchronously.

Parameters:

console (IAnsiConsole)
The console.
cancellationToken (CancellationToken)
The token to monitor for cancellation requests.

Returns:

The prompt input result.

Extension Methods

TextPrompt<T> AllowEmpty<T>(this TextPrompt<T> obj)

Allow empty input.

Returns:

The same instance so that multiple calls can be chained.