API Reference
MenuItem
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.
Returned or exposed by 21
- Method Menu.Find
- Property Menu.Items
- Property MenuContext.Item
- Method MenuItem.Action
- Method MenuItem.ActionAsync
- Method MenuItem.Badge
- Method MenuItem.Describe
- Method MenuItem.Disabled
- Method MenuItem.Form
- Method MenuItem.Hotkey
- Method MenuItem.LoadChoices
- Method MenuItem.MultiSelect``1
- Method MenuItem.Page
- Method MenuItem.Presets
- Method MenuItem.Review
- Method MenuItem.Select``1
- Method MenuItem.State
- Method MenuItem.Submenu
- Method MenuItem.WithIcon
- Property ReviewModel.Fixes
- Property RunResult.NextActions
Accepted by parameters 4
- Method Menu.Add
- Method Menu.Item
- Method MenuContext.Open
- Method ReviewModel.Problem
Constructors
Methods
public MenuItem Badge(Func<String?> badge) #MenuItemSets a computed badge.
Parameters
- badge System.Func<System.String?>
- Returns the badge text.
Returns
The item.
public MenuItem Badge(Func<RichText?> badge) #MenuItemSets a computed styled badge.
Parameters
- badge System.Func<ConsoleMonster.Text.RichText?>
- Returns the badge.
Returns
The item.
public MenuItem Describe(String text) #MenuItemSets the description.
Parameters
- text System.String
- The text.
Returns
The item.
public MenuItem Disabled(Func<String?> reason) #MenuItemMakes the item unavailable while the function returns a reason.
Parameters
- reason System.Func<System.String?>
- Returns the reason, or null when available.
Returns
The item.
public IReadOnlyList<T?> GetSelection<T>() #IReadOnlyList<T?>The selection as typed values.
Type Parameters
- T
- The value type.
Returns
The values.
public MenuItem Hotkey(Char key) #MenuItemSets the hotkey.
Parameters
- key System.Char
- The key.
Returns
The item.
public String? IconText(IGlyphSet glyphs) #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
- The glyph set.
Returns
The icon text, or null.
public MenuItem MultiSelect<T>(IEnumerable<T?> values, Func<T?, String>? display = null, Func<T?, String?>? group = null, Func<T?, IWidget?>? preview = null) #MenuItemMakes the item pick several values.
Type Parameters
- T
- The value type.
Parameters
- values System.Collections.Generic.IEnumerable<T?>
- The values.
- display System.Func<T?, System.String>? = null
- The title of a value.
- group System.Func<T?, System.String?>? = null
- The group of a value.
- preview System.Func<T?, ConsoleMonster.Layout.IWidget?>? = null
- Preview content for a value.
Returns
The item.
public MenuItem Presets() #MenuItemMakes the item list the menu's saved presets (Enter applies one, Delete removes it).
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) #MenuItemMakes the item pick one value.
Type Parameters
- T
- The value type.
Parameters
- values System.Collections.Generic.IEnumerable<T?>
- The values.
- display System.Func<T?, System.String>? = null
- The title of a value.
- group System.Func<T?, System.String?>? = null
- The group of a value.
- preview System.Func<T?, ConsoleMonster.Layout.IWidget?>? = null
- Preview content for a value.
Returns
The item.
public Void SetSelection(IEnumerable<Object?> values) #VoidSets the selected values of a selection item (pre-selection, presets, programmatic changes).
Parameters
- values System.Collections.Generic.IEnumerable<System.Object?>
- The values.
public MenuItem State(Func<String?> state) #MenuItemSets computed state text.
Parameters
- state System.Func<System.String?>
- Returns the state.
Returns
The item.
public override String ToString() #StringReturns a string that represents the current object.
Returns
A string that represents the current object.
public MenuItem WithIcon(String icon) #MenuItemSets the icon.
Parameters
- icon System.String
- One or two cells.
Returns
The item.
Inherited Methods
Properties
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 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 Func<MenuContext, CancellationToken, Task>? AsyncHandler { get; set; } #The asynchronous action of an action item (runs without blocking the screen; Esc cancels it).
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 Func<Choice, IWidget?>? Preview { get; set; } #Preview content for the focused choice of a 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.