Skip to content
ConsoleMonster
Class

ChoiceField

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Base
Field
Modifiers
sealed

One or several values from a list, given up front or loaded asynchronously from the values of the fields it depends on (choosing a site loads its servers): a spinner shows while loading, and loading can be cancelled.

Inheritance

Usage

Explore 68 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 32

Constructors

public ChoiceField(string key, string? label = null, bool multiple = false) #

Creates a choice field.

Parameters

key string required
The key.
label string? = null optional
The label.
multiple bool = false optional
Whether several values can be chosen.

Methods

public override string Display(object? value, PromptLabels labels) #

The value as shown in the form and on the review page.

Parameters

value object? required
The value.
labels ConsoleMonster.Interactive.PromptLabels required
The labels.

Returns

string The text.

Properties

public override FieldKind Kind { get; } #

The kind.

public bool Multiple { get; } #

Whether several values can be chosen.

public IList<Choice> Choices { get; } #

The choices (replaced by the loader's result when one is set).

public Func<FormValues, CancellationToken, Task<IEnumerable<Choice>>>? LoadChoices { get; set; } #
Fluent("ChoicesBy")

Loads the choices from the current values (dependent fields).

public int? Minimum { get; set; } #

The fewest values (multiple).

public int? Maximum { get; set; } #

The most values (multiple).

public Func<Choice, IWidget?>? Preview { get; set; } #
Fluent("PreviewBy")

Preview content for the focused choice in the editor.

Extension Methods

public static ChoiceField Choice(ChoiceField choiceField, Choice item) #

Adds an item to ChoiceField.Choices: The choices (replaced by the loader's result when one is set).

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
item ConsoleMonster.Interactive.Choice required
The item.

Returns

ChoiceField The same instance.
public static ChoiceField Choices(ChoiceField choiceField, IEnumerable<Choice> items) #

Adds items to ChoiceField.Choices: The choices (replaced by the loader's result when one is set).

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.Choice> required
The items, in order.

Returns

ChoiceField The same instance.
public static ChoiceField ChoicesBy(ChoiceField choiceField, Func<FormValues, CancellationToken, Task<IEnumerable<Choice>>>? value) #

Sets ChoiceField.LoadChoices: Loads the choices from the current values (dependent fields).

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value System.Func<ConsoleMonster.Interactive.FormValues, System.Threading.CancellationToken, System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.Choice>>>? required
The callback.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property       // C# fluent
choiceField.LoadChoices = value;    choiceField.ChoicesBy(value);
public static ChoiceField Default(ChoiceField choiceField, object? value) #

Sets Field.Default: The declared default: the starting value until a value is set, and values equal to it are left out of the equivalent command.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value object? required
The value.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Default = value;     choiceField.Default(value);
DependsOn 2 overloads
public static ChoiceField DependsOn(ChoiceField choiceField, string item) #

Adds an item to Field.DependsOn: Fields whose change resets this field (and reloads its options).

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
item string required
The item.

Returns

ChoiceField The same instance.
public static ChoiceField DependsOn(ChoiceField choiceField, IEnumerable<string> items) #

Adds items to Field.DependsOn: Fields whose change resets this field (and reloads its options).

Parameters

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

Returns

ChoiceField The same instance.
public static ChoiceField Help(ChoiceField choiceField, string? value) #

Sets Field.Help: Help shown while the field has focus.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value string? required
The value.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Help = value;        choiceField.Help(value);
public static ChoiceField Label(ChoiceField choiceField, string value) #

Sets Field.Label: The label.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value string required
The value.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Label = value;       choiceField.Label(value);
public static ChoiceField Maximum(ChoiceField choiceField, int? value) #

Sets ChoiceField.Maximum: The most values (multiple).

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value int? required
The value.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Maximum = value;     choiceField.Maximum(value);
public static ChoiceField Minimum(ChoiceField choiceField, int? value) #

Sets ChoiceField.Minimum: The fewest values (multiple).

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value int? required
The value.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Minimum = value;     choiceField.Minimum(value);
public static ChoiceField ParameterName(ChoiceField choiceField, string? value) #

Sets Field.ParameterName: The command-line parameter this field supplies (Domain, -Domain, --domain); null leaves the field out of the equivalent command.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value string? required
The value.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property         // C# fluent
choiceField.ParameterName = value;    choiceField.ParameterName(value);
public static ChoiceField PreviewBy(ChoiceField choiceField, Func<Choice, IWidget?>? value) #

Sets ChoiceField.Preview: Preview content for the focused choice in the editor.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value System.Func<ConsoleMonster.Interactive.Choice, ConsoleMonster.Layout.IWidget?>? required
The callback.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Preview = value;     choiceField.PreviewBy(value);
public static ChoiceField Remember(ChoiceField choiceField, bool value = true) #

Sets Field.Remember: Whether the value is kept in presets and remembered choices (never for secrets).

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value bool = true optional
The value; true when omitted.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Remember = value;    choiceField.Remember(value);
public static ChoiceField Required(ChoiceField choiceField, bool value = true) #

Sets Field.Required: Whether an empty value is refused.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value bool = true optional
The value; true when omitted.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Required = value;    choiceField.Required(value);
public static ChoiceField ShowWhen(ChoiceField choiceField, Func<FormValues, bool>? value) #

Sets Field.VisibleWhen: Shows the field only while this returns true.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value System.Func<ConsoleMonster.Interactive.FormValues, bool>? required
The callback.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property       // C# fluent
choiceField.VisibleWhen = value;    choiceField.ShowWhen(value);
public static ChoiceField Validate(ChoiceField choiceField, Func<object?, FormValues, string?>? value) #

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

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value System.Func<object?, ConsoleMonster.Interactive.FormValues, string?>? required
The callback.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property     // C# fluent
choiceField.Validator = value;    choiceField.Validate(value);
public static ChoiceField Value(ChoiceField choiceField, object? value) #

Sets Field.Value: The current value.

Parameters

choiceField ConsoleMonster.Interactive.ChoiceField required
The instance.
value object? required
The value.

Returns

ChoiceField The same instance.

Examples

// C# initializer or property    // C# fluent
choiceField.Value = value;       choiceField.Value(value);