Skip to content
ConsoleMonster
Class

TextPrompt

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Modifiers
sealed

A line of text: a default (shown as a hint, accepted with Enter on an empty line, Tab puts it in the box to edit), a placeholder, required/length/pattern checks and a custom validator with an inline error, and history on Up/Down.

Inheritance

Usage

Explore 52 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 26

Constructors

public TextPrompt(string title) #

Creates a text prompt.

Parameters

title string required
The question.

Methods

public override string Describe(string value) #

The answer as text, for the summary line left in the scrollback.

Parameters

value string required
The answer.

Returns

string The text.

Properties

public string? Placeholder { get; set; } #

Muted text in the empty box.

public bool Required { get; set; } #

Whether an empty answer is refused (when there is no default).

public int MinLength { get; set; } #

The fewest characters accepted.

public int MaxLength { get; set; } #

The most characters the box takes.

public string? Pattern { get; set; } #

A pattern the whole answer must match.

public string? PatternMessage { get; set; } #

The message when TextPrompt.Pattern does not match.

public Func<string, string?>? Validator { get; set; } #
Fluent("Validate")

A validator: returns an error message, or null when the answer is fine.

public IList<string> History { get; } #

Earlier answers offered with Up and Down (oldest first).

public bool PrefillDefault { get; set; } #

Starts with the default in the box (editable) instead of showing it as a hint.

Extension Methods

public static TextPrompt Default(TextPrompt textPrompt, string value) #

Sets Prompt<string>.Default: The default answer: pre-selected, accepted with Enter, and returned in non-interactive sessions.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value string required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
textPrompt.Default = value;      textPrompt.Default(value);
public static TextPrompt Description(TextPrompt textPrompt, string? value) #

Sets Prompt<string>.Description: Help text under the question.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value string? required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property      // C# fluent
textPrompt.Description = value;    textPrompt.Description(value);
History 2 overloads
public static TextPrompt History(TextPrompt textPrompt, string item) #

Adds an item to TextPrompt.History: Earlier answers offered with Up and Down (oldest first).

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
item string required
The item.

Returns

TextPrompt The same instance.
public static TextPrompt History(TextPrompt textPrompt, IEnumerable<string> items) #

Adds items to TextPrompt.History: Earlier answers offered with Up and Down (oldest first).

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
items System.Collections.Generic.IEnumerable<string> required
The items, in order.

Returns

TextPrompt The same instance.
public static TextPrompt MaxLength(TextPrompt textPrompt, int value) #

Sets TextPrompt.MaxLength: The most characters the box takes.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value int required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
textPrompt.MaxLength = value;    textPrompt.MaxLength(value);
public static TextPrompt MinLength(TextPrompt textPrompt, int value) #

Sets TextPrompt.MinLength: The fewest characters accepted.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value int required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
textPrompt.MinLength = value;    textPrompt.MinLength(value);
public static TextPrompt ParameterName(TextPrompt textPrompt, string? value) #

Sets Prompt<string>.ParameterName: The parameter that supplies this value non-interactively (-Domain, --domain); named in the non-interactive error message.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value string? required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property        // C# fluent
textPrompt.ParameterName = value;    textPrompt.ParameterName(value);
public static TextPrompt Pattern(TextPrompt textPrompt, string? value) #

Sets TextPrompt.Pattern: A pattern the whole answer must match.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value string? required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
textPrompt.Pattern = value;      textPrompt.Pattern(value);
public static TextPrompt PatternMessage(TextPrompt textPrompt, string? value) #

Sets TextPrompt.PatternMessage: The message when TextPrompt.Pattern does not match.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value string? required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property         // C# fluent
textPrompt.PatternMessage = value;    textPrompt.PatternMessage(value);
public static TextPrompt Placeholder(TextPrompt textPrompt, string? value) #

Sets TextPrompt.Placeholder: Muted text in the empty box.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value string? required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property      // C# fluent
textPrompt.Placeholder = value;    textPrompt.Placeholder(value);
public static TextPrompt PrefillDefault(TextPrompt textPrompt, bool value = true) #

Sets TextPrompt.PrefillDefault: Starts with the default in the box (editable) instead of showing it as a hint.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value bool = true optional
The value; true when omitted.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property         // C# fluent
textPrompt.PrefillDefault = value;    textPrompt.PrefillDefault(value);
public static TextPrompt Required(TextPrompt textPrompt, bool value = true) #

Sets TextPrompt.Required: Whether an empty answer is refused (when there is no default).

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value bool = true optional
The value; true when omitted.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
textPrompt.Required = value;     textPrompt.Required(value);
public static TextPrompt Title(TextPrompt textPrompt, string value) #

Sets Prompt<string>.Title: The question.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value string required
The value.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
textPrompt.Title = value;        textPrompt.Title(value);
public static TextPrompt Validate(TextPrompt textPrompt, Func<string, string?>? value) #

Sets TextPrompt.Validator: A validator: returns an error message, or null when the answer is fine.

Parameters

textPrompt ConsoleMonster.Interactive.TextPrompt required
The instance.
value System.Func<string, string?>? required
The callback.

Returns

TextPrompt The same instance.

Examples

// C# initializer or property    // C# fluent
textPrompt.Validator = value;    textPrompt.Validate(value);