Skip to content
ConsoleMonster
Class

Choice

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Modifiers
sealed
Attributes
Fluent

One option in a selection prompt, menu or choice field: the value returned when it is chosen, the title shown, and optional group, description, hotkey, badge, disabled reason and initial selection.

Inheritance

  • object
  • Choice

Usage

Explore 86 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 55

Constructors

public Choice(object? value, string? label = null) #

Creates a choice.

Parameters

value object? required
The value returned when chosen (any object).
label string? = null optional
The title shown; null uses the value's text.

Methods

public static List<Choice> From<T>(IEnumerable<T?> choices, Func<T?, string>? display = null, Func<T?, string?>? groupBy = null, Func<T?, string?>? describe = null, Func<T?, RichText?>? badge = null, Func<T?, string?>? disabledReason = null) #

Builds choices from values using the shared display and metadata selectors.

Type Parameters

T
The value type.

Parameters

choices System.Collections.Generic.IEnumerable<T?> required
The choices.
display System.Func<T?, string>? = null optional
The label for a value; null uses its text.
groupBy System.Func<T?, string?>? = null optional
The group heading for a value, or null.
describe System.Func<T?, string?>? = null optional
Help text for a value, or null.
badge System.Func<T?, ConsoleMonster.Text.RichText?>? = null optional
A styled badge for a value, or null.
disabledReason System.Func<T?, string?>? = null optional
Why a value cannot be selected; null or empty keeps it enabled.

Returns

List<Choice> The choices.
public override string ToString() #

Returns a string that represents the current object.

Returns

string A string that represents the current object.

Properties

public object? Value { get; } #

The value returned when chosen.

public string Label { get; set; } #

The title, also what the filter matches.

public RichText? RichTitle { get; set; } #

A styled title shown instead of Choice.Label while no filter is active.

public string? Description { get; set; } #

A sentence shown under the list while the choice has focus.

public string? Group { get; set; } #

The group heading the choice is listed under.

public char? Hotkey { get; set; } #

A key that picks the choice directly (letters and digits).

public RichText? Badge { get; set; } #

Short right-aligned text: a count, a state, a tag ("new", "24 tasks").

public string? DisabledReason { get; set; } #

Why the choice cannot be picked; null when it can. Disabled choices are dimmed and show the reason on focus.

public bool Selected { get; set; } #

Whether a multi-selection starts with this choice selected.

public IWidget? Preview { get; set; } #

Content for the preview pane while the choice has focus (overrides the prompt's preview function).

public object? Tag { get; set; } #

Any extra object for the caller.

public bool IsEnabled { get; } #

Whether the choice can be picked.

Extension Methods

Badge 2 overloads
public static Choice Badge(Choice choice, RichText? value) #

Sets Choice.Badge: Short right-aligned text: a count, a state, a tag ("new", "24 tasks").

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value ConsoleMonster.Text.RichText? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Badge = value;            choice.Badge(value);
public static Choice Badge(Choice choice, Action<RichText> configure) #

Configures Choice.Badge in place: Short right-aligned text: a count, a state, a tag ("new", "24 tasks").

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
configure System.Action<ConsoleMonster.Text.RichText> required
Configures the value.

Returns

Choice The same instance.
public static Choice Description(Choice choice, string? value) #

Sets Choice.Description: A sentence shown under the list while the choice has focus.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value string? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Description = value;      choice.Description(value);
public static Choice DisabledReason(Choice choice, string? value) #

Sets Choice.DisabledReason: Why the choice cannot be picked; null when it can. Disabled choices are dimmed and show the reason on focus.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value string? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property     // C# fluent
choice.DisabledReason = value;    choice.DisabledReason(value);
public static Choice Group(Choice choice, string? value) #

Sets Choice.Group: The group heading the choice is listed under.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value string? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Group = value;            choice.Group(value);
public static Choice Hotkey(Choice choice, char? value) #

Sets Choice.Hotkey: A key that picks the choice directly (letters and digits).

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value char? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Hotkey = value;           choice.Hotkey(value);
public static Choice Label(Choice choice, string value) #

Sets Choice.Label: The title, also what the filter matches.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value string required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Label = value;            choice.Label(value);
public static Choice Preview(Choice choice, IWidget? value) #

Sets Choice.Preview: Content for the preview pane while the choice has focus (overrides the prompt's preview function).

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value ConsoleMonster.Layout.IWidget? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Preview = value;          choice.Preview(value);
RichTitle 2 overloads
public static Choice RichTitle(Choice choice, RichText? value) #

Sets Choice.RichTitle: A styled title shown instead of Choice.Label while no filter is active.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value ConsoleMonster.Text.RichText? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.RichTitle = value;        choice.RichTitle(value);
public static Choice RichTitle(Choice choice, Action<RichText> configure) #

Configures Choice.RichTitle in place: A styled title shown instead of Choice.Label while no filter is active.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
configure System.Action<ConsoleMonster.Text.RichText> required
Configures the value.

Returns

Choice The same instance.
public static Choice Selected(Choice choice, bool value = true) #

Sets Choice.Selected: Whether a multi-selection starts with this choice selected.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Selected = value;         choice.Selected(value);
public static Choice Tag(Choice choice, object? value) #

Sets Choice.Tag: Any extra object for the caller.

Parameters

choice ConsoleMonster.Interactive.Choice required
The instance.
value object? required
The value.

Returns

Choice The same instance.

Examples

// C# initializer or property    // C# fluent
choice.Tag = value;              choice.Tag(value);