Skip to content
ConsoleMonster

API Reference

Class

MenuItem

Namespace ConsoleMonster.Interactive
Assembly ConsoleMonster
Modifiers sealed

An entry of a Menu: title, description, hotkey, icon, badge, state text, a disabled reason, and what it opens (an action, a submenu, a form, a selection, a page). Configure it with the chainable methods: item.Hotkey('r').Form(form).Badge(() => "24 tasks").

Inheritance

  • Object
  • MenuItem

Usage

Explore 25 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 4

Constructors

public MenuItem(String title) #

Creates an item.

Parameters

title System.String requiredposition: 0
The title.

Methods

public MenuItem Action(Action<MenuContext> action) #
Returns: MenuItem

Makes the item run an action.

Parameters

action System.Action<ConsoleMonster.Interactive.MenuContext> requiredposition: 0
The action.

Returns

The item.

public MenuItem ActionAsync(Func<MenuContext, CancellationToken, Task> action) #
Returns: MenuItem

Makes the item run an asynchronous action.

Parameters

action System.Func<ConsoleMonster.Interactive.MenuContext, System.Threading.CancellationToken, System.Threading.Tasks.Task> requiredposition: 0
The action.

Returns

The item.

Badge 2 overloads
public MenuItem Badge(Func<String?> badge) #
Returns: MenuItem

Sets a computed badge.

Parameters

badge System.Func<System.String?> requiredposition: 0
Returns the badge text.

Returns

The item.

public MenuItem Badge(Func<RichText?> badge) #
Returns: MenuItem

Sets a computed styled badge.

Parameters

badge System.Func<ConsoleMonster.Text.RichText?> requiredposition: 0
Returns the badge.

Returns

The item.

public MenuItem Describe(String text) #
Returns: MenuItem

Sets the description.

Parameters

text System.String requiredposition: 0
The text.

Returns

The item.

public MenuItem Disabled(Func<String?> reason) #
Returns: MenuItem

Makes the item unavailable while the function returns a reason.

Parameters

reason System.Func<System.String?> requiredposition: 0
Returns the reason, or null when available.

Returns

The item.

public MenuItem Form(Form form, Action<MenuContext, FormResult>? submitted = null) #
Returns: MenuItem

Makes the item open a form.

Parameters

form ConsoleMonster.Interactive.Form requiredposition: 0
The form.
submitted System.Action<ConsoleMonster.Interactive.MenuContext, ConsoleMonster.Interactive.FormResult>? = null optionalposition: 1
Called when it is submitted.

Returns

The item.

public IReadOnlyList<T?> GetSelection<T>() #
Returns: IReadOnlyList<T?>

The selection as typed values.

Type Parameters

T
The value type.

Returns

The values.

public MenuItem Hotkey(Char key) #
Returns: MenuItem

Sets the hotkey.

Parameters

key System.Char requiredposition: 0
The key.

Returns

The item.

public String? IconText(IGlyphSet glyphs) #
Returns: String?

The icon text for a glyph set: the semantic icon in its tier, else the free text, else null.

Parameters

glyphs ConsoleMonster.Glyphs.IGlyphSet requiredposition: 0
The glyph set.

Returns

The icon text, or null.

public MenuItem LoadChoices(Func<MenuContext, CancellationToken, Task<IEnumerable<Choice>>> loader, Boolean multiple = true) #
Returns: MenuItem

Loads the choices of a selection item asynchronously instead of listing them up front.

Parameters

loader System.Func<ConsoleMonster.Interactive.MenuContext, System.Threading.CancellationToken, System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.Choice>>> requiredposition: 0
Returns the choices.
multiple System.Boolean = true optionalposition: 1
Whether several values can be picked.

Returns

The item.

public MenuItem MultiSelect<T>(IEnumerable<T?> values, Func<T?, String>? display = null, Func<T?, String?>? group = null, Func<T?, IWidget?>? preview = null) #
Returns: MenuItem

Makes the item pick several values.

Type Parameters

T
The value type.

Parameters

values System.Collections.Generic.IEnumerable<T?> requiredposition: 0
The values.
display System.Func<T?, System.String>? = null optionalposition: 1
The title of a value.
group System.Func<T?, System.String?>? = null optionalposition: 2
The group of a value.
preview System.Func<T?, ConsoleMonster.Layout.IWidget?>? = null optionalposition: 3
Preview content for a value.

Returns

The item.

public MenuItem Page(Func<MenuContext, IWidget> page) #
Returns: MenuItem

Makes the item show content.

Parameters

page System.Func<ConsoleMonster.Interactive.MenuContext, ConsoleMonster.Layout.IWidget> requiredposition: 0
Builds the content each time it is drawn.

Returns

The item.

public MenuItem Presets() #
Returns: MenuItem

Makes the item list the menu's saved presets (Enter applies one, Delete removes it).

Returns

The item.

public MenuItem Review(Func<MenuContext, ReviewModel> review) #
Returns: MenuItem

Makes the item show a review (summary, equivalent command, Run, Copy command, Save preset).

Parameters

review System.Func<ConsoleMonster.Interactive.MenuContext, ConsoleMonster.Interactive.ReviewModel> requiredposition: 0
Builds the review from the app's current state.

Returns

The item.

public MenuItem Select<T>(IEnumerable<T?> values, Func<T?, String>? display = null, Func<T?, String?>? group = null, Func<T?, IWidget?>? preview = null) #
Returns: MenuItem

Makes the item pick one value.

Type Parameters

T
The value type.

Parameters

values System.Collections.Generic.IEnumerable<T?> requiredposition: 0
The values.
display System.Func<T?, System.String>? = null optionalposition: 1
The title of a value.
group System.Func<T?, System.String?>? = null optionalposition: 2
The group of a value.
preview System.Func<T?, ConsoleMonster.Layout.IWidget?>? = null optionalposition: 3
Preview content for a value.

Returns

The item.

public Void SetSelection(IEnumerable<Object?> values) #
Returns: Void

Sets the selected values of a selection item (pre-selection, presets, programmatic changes).

Parameters

values System.Collections.Generic.IEnumerable<System.Object?> requiredposition: 0
The values.
public MenuItem State(Func<String?> state) #
Returns: MenuItem

Sets computed state text.

Parameters

state System.Func<System.String?> requiredposition: 0
Returns the state.

Returns

The item.

Submenu 2 overloads
public MenuItem Submenu(Menu menu) #
Returns: MenuItem

Makes the item open a submenu.

Parameters

menu ConsoleMonster.Interactive.Menu requiredposition: 0
The submenu.

Returns

The item.

public MenuItem Submenu(Action<Menu> configure) #
Returns: MenuItem

Makes the item open a submenu built in place.

Parameters

configure System.Action<ConsoleMonster.Interactive.Menu> requiredposition: 0
Adds the submenu's items.

Returns

The item.

public override String ToString() #
Returns: String

Returns a string that represents the current object.

Returns

A string that represents the current object.

WithIcon 2 overloads
public MenuItem WithIcon(String icon) #
Returns: MenuItem

Sets the icon.

Parameters

icon System.String requiredposition: 0
One or two cells.

Returns

The item.

public MenuItem WithIcon(GlyphIcon icon) #
Returns: MenuItem

Sets a semantic icon that follows the glyph tier (see GlyphIcon).

Parameters

icon ConsoleMonster.Glyphs.GlyphIcon requiredposition: 0
The icon.

Returns

The item.

Properties

public String Title { get; set; } #

The title.

public String? Description { get; set; } #

A sentence shown with the item.

public Char? HotkeyChar { get; set; } #

The key that opens the item directly.

public String? Icon { get; set; } #

A short mark before the title (one or two cells), as free text. MenuItem.IconGlyph takes precedence.

public GlyphIcon? IconGlyph { get; set; } #

A semantic icon resolved for the glyph tier (shapes in Full, WGL4 in Basic, ASCII in Ascii), or null.

public MenuItemKind Kind { get; set; } #

What the item does.

public Func<RichText?>? BadgeSource { get; set; } #

Computes the badge (right-aligned tag) each time the menu is drawn.

public Func<String?>? StateSource { get; set; } #

Computes the state text ("24 selected") each time the menu is drawn.

public Func<String?>? DisabledSource { get; set; } #

Computes why the item is unavailable (null when available).

public Action<MenuContext>? Handler { get; set; } #

The action of an action item.

public Func<MenuContext, CancellationToken, Task>? AsyncHandler { get; set; } #

The asynchronous action of an action item (runs without blocking the screen; Esc cancels it).

public Menu? SubmenuDefinition { get; set; } #

The submenu of a submenu item.

public Form? FormDefinition { get; set; } #

The form of a form item.

public Action<MenuContext, FormResult>? FormSubmitted { get; set; } #

Called when the form is submitted.

public Func<MenuContext, IWidget>? PageFactory { get; set; } #

Builds the content of a page item.

public IList<Choice> Choices { get; } #

The choices of a selection item.

public Func<Choice, IWidget?>? Preview { get; set; } #

Preview content for the focused choice of a selection item.

public Int32? Minimum { get; set; } #

The fewest values of a multi-selection item.

public Int32? Maximum { get; set; } #

The most values of a multi-selection item.

public Func<MenuContext, CancellationToken, Task<IEnumerable<Choice>>>? ChoicesLoader { get; set; } #

Loads the choices of a selection item asynchronously (a spinner shows meanwhile; Ctrl+R reloads).

public Func<MenuContext, ReviewModel>? ReviewFactory { get; set; } #

Builds the review of a review item each time it is drawn.

public Action<MenuContext>? SelectionChanged { get; set; } #

Called when the selection of a selection item changes.

public IReadOnlyList<Object?> Selection { get; } #

The selected values of a selection item, in list order.

public Object? SelectedValue { get; } #

The selected value of a single-selection item, or null.

public RichText? CurrentBadge { get; } #

The badge now.

public String? CurrentState { get; } #

The state text now.

public String? CurrentDisabledReason { get; } #

The disabled reason now, or null.