TextPrompt<T> Class

Represents a prompt.
public sealed class TextPrompt<T> : IPrompt<T>, IHasCulture
Namespace
Spectre.Console
Interfaces

Parameters

T
The prompt result type.

Constructors

TextPrompt(string, StringComparer)
Initializes a new instance of the TextPrompt<T> class.

Properties

bool AllowEmpty
Gets or sets a value indicating whether or not an empty result is valid.
List<T> Choices
Gets the list of choices.
Style ChoicesStyle
Gets or sets the style in which the list of choices is displayed. Defaults to blue when .
Func<T, string> Converter
Gets or sets the converter to get the display string for a choice. By default the corresponding TypeConverter is used.
CultureInfo Culture
Gets or sets the culture to use when converting input to object.
Style DefaultValueStyle
Gets or sets the style in which the default value is displayed. Defaults to green when .
string InvalidChoiceMessage
Gets or sets the message for invalid choices.
bool IsSecret
Gets or sets a value indicating whether input should be hidden in the console.
char? Mask
Gets or sets the character to use while masking a secret prompt.
Style PromptStyle
Gets or sets the prompt style.
bool ShowChoices
Gets or sets a value indicating whether or not choices should be shown.
bool ShowDefaultValue
Gets or sets a value indicating whether or not default values should be shown.
string ValidationErrorMessage
Gets or sets the validation error message.
Func<T, ValidationResult> Validator
Gets or sets the validator.

Methods

T Show(IAnsiConsole)
Shows the prompt and requests input from the user.
Task<T> ShowAsync(IAnsiConsole, CancellationToken)
Shows the prompt asynchronously.

Extension Methods

TextPrompt<T> AddChoice<T>(T)
Adds a choice to the prompt.
TextPrompt<T> AddChoices<T>(IEnumerable<T>)
Adds multiple choices to the prompt.
TextPrompt<T> AllowEmpty<T>()
Allow empty input.
TextPrompt<T> ChoicesStyle<T>(Style)
Sets the style in which the list of choices is displayed.
T Culture<TextPrompt<T>>(int)
Sets the culture.
T Culture<TextPrompt<T>>(string)
Sets the culture.
TextPrompt<T> DefaultValue<T>(T)
Sets the default value of the prompt.
TextPrompt<T> DefaultValueStyle<T>(Style)
Sets the style in which the default value is displayed.
TextPrompt<T> HideChoices<T>()
Hides choices.
TextPrompt<T> HideDefaultValue<T>()
Hides the default value.
TextPrompt<T> InvalidChoiceMessage<T>(string)
Sets the "invalid choice" message for the prompt.
TextPrompt<T> PromptStyle<T>(Style)
Sets the prompt style.
TextPrompt<T> Secret<T>(char?)
Replaces prompt user input with mask in the console.
TextPrompt<T> Secret<T>()
Replaces prompt user input with asterisks in the console.
TextPrompt<T> ShowChoices<T>(bool)
Show or hide choices.
TextPrompt<T> ShowChoices<T>()
Shows choices.
TextPrompt<T> ShowDefaultValue<T>(bool)
Show or hide the default value.
TextPrompt<T> ShowDefaultValue<T>()
Shows the default value.
TextPrompt<T> Validate<T>(Func<T, bool>, string)
Sets the validation criteria for the prompt.
TextPrompt<T> Validate<T>(Func<T, ValidationResult>)
Sets the validation criteria for the prompt.
TextPrompt<T> ValidationErrorMessage<T>(string)
Sets the validation error message for the prompt.
TextPrompt<T> WithConverter<T>(Func<T, string>)
Sets the function to create a display string for a given choice.