Skip to content
ConsoleMonster
Class

Menu

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Modifiers
sealed
Attributes
Fluent

A menu tree: items that run actions, open submenus, forms, selections and pages. Run shows it as an app (Shell), a centred menu (Classic) or a scrollback list (Inline), with a breadcrumb, Back/Home/Exit, the command palette (Ctrl+K or :), the key map (?) and a footer generated from the active keys.

Inheritance

  • object
  • Menu

Usage

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

Accepted by parameters 29

Constructors

public Menu(string title) #

Creates a menu.

Parameters

title string required
The title (the app name for the root menu).

Methods

public Menu Add(MenuItem item) #

Adds an item.

Parameters

item ConsoleMonster.Interactive.MenuItem required
The item.

Returns

Menu The menu.
public Menu Exit(string? title = null) #

Adds the exit item.

Parameters

title string? = null optional
The title; null uses "Exit".

Returns

Menu The menu.
public MenuItem? Find(string title) #

Finds an item by title anywhere in the tree.

Parameters

title string required
The title.

Returns

MenuItem? The item, or null.
public Menu Item(string title, Action<MenuItem>? configure = null) #

Adds an item and configures it.

Parameters

title string required
The title.
configure System.Action<ConsoleMonster.Interactive.MenuItem>? = null optional
Configures the item.

Returns

Menu The menu.
public Menu Preset(string name, Action<MenuPreset> configure) #

Adds a built-in preset and configures it (see Menu.Presets).

Parameters

name string required
The name; a saved preset cannot take it.
configure System.Action<ConsoleMonster.Interactive.MenuPreset> required
Sets what the preset selects and fills in.

Returns

Menu The menu.
Run 2 overloads
public void Run(Action<MenuOptions> configure, CancellationToken cancellationToken = default) #

Runs this menu with freshly configured options.

Parameters

configure System.Action<ConsoleMonster.Interactive.MenuOptions> required
Menu settings.
cancellationToken System.Threading.CancellationToken = default optional
Cancellation.
public void Run(MenuOptions? options = null, CancellationToken cancellationToken = default) #

Shows the menu until the user exits.

Parameters

options ConsoleMonster.Interactive.MenuOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
Ends the menu.
RunAsync 2 overloads
public Task RunAsync(Action<MenuOptions> configure, CancellationToken cancellationToken = default) #

Runs this menu asynchronously with freshly configured options.

Parameters

configure System.Action<ConsoleMonster.Interactive.MenuOptions> required
Menu settings.
cancellationToken System.Threading.CancellationToken = default optional
Cancellation.

Returns

Task The menu task.
public Task RunAsync(MenuOptions? options = null, CancellationToken cancellationToken = default) #

Shows the menu on a worker thread until the user exits.

Parameters

options ConsoleMonster.Interactive.MenuOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
Ends the menu.

Returns

Task Completion.
public Menu Separator(string? title = null) #

Adds a divider with an optional heading.

Parameters

title string? = null optional
The heading, or null.

Returns

Menu The menu.

Properties

public string Title { get; set; } #

The title.

public string? Description { get; set; } #

A sentence shown above the items.

public string? Subtitle { get; set; } #

Muted text at the right of the title bar (a version, an environment).

public MenuLayout Layout { get; set; } #

The layout this menu prefers when MenuOptions.Layout is Auto.

public IList<MenuItem> Items { get; } #

The items.

public IList<ICommandProvider> CommandProviders { get; } #

Extra sources for the command palette.

public IList<KeyBinding> KeyBindings { get; } #

App-wide key bindings (shown in the key map and, by priority, in the footer).

public IList<MenuPreset> Presets { get; } #

The presets the app comes with (declared on the root menu): a MenuItem.Presets item lists them before the presets people save, marked as built in; they cannot be overwritten or deleted. A saved preset whose name matches a built-in one (ignoring case) is hidden.

Extension Methods

public static Menu CommandProvider(Menu menu, ICommandProvider item) #

Adds an item to Menu.CommandProviders: Extra sources for the command palette.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
item ConsoleMonster.Interactive.ICommandProvider required
The item.

Returns

Menu The same instance.
public static Menu CommandProviders(Menu menu, IEnumerable<ICommandProvider> items) #

Adds items to Menu.CommandProviders: Extra sources for the command palette.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.ICommandProvider> required
The items, in order.

Returns

Menu The same instance.
public static Menu Description(Menu menu, string? value) #

Sets Menu.Description: A sentence shown above the items.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
value string? required
The value.

Returns

Menu The same instance.

Examples

// C# initializer or property    // C# fluent
menu.Description = value;        Ui.Menu().Description(value);
public static Menu Item(Menu menu, MenuItem item) #

Adds an item to Menu.Items: The items.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
item ConsoleMonster.Interactive.MenuItem required
The item.

Returns

Menu The same instance.
public static Menu Items(Menu menu, IEnumerable<MenuItem> items) #

Adds items to Menu.Items: The items.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.MenuItem> required
The items, in order.

Returns

Menu The same instance.
public static Menu KeyBinding(Menu menu, KeyBinding item) #

Adds an item to Menu.KeyBindings: App-wide key bindings (shown in the key map and, by priority, in the footer).

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
item ConsoleMonster.Interactive.KeyBinding required
The item.

Returns

Menu The same instance.
public static Menu KeyBindings(Menu menu, IEnumerable<KeyBinding> items) #

Adds items to Menu.KeyBindings: App-wide key bindings (shown in the key map and, by priority, in the footer).

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.KeyBinding> required
The items, in order.

Returns

Menu The same instance.
public static Menu Layout(Menu menu, MenuLayout value) #

Sets Menu.Layout: The layout this menu prefers when MenuOptions.Layout is Auto.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
value ConsoleMonster.Interactive.MenuLayout required
The value.

Returns

Menu The same instance.

Examples

// C# initializer or property    // C# fluent
menu.Layout = value;             Ui.Menu().Layout(value);
public static Menu Preset(Menu menu, MenuPreset item) #

Adds an item to Menu.Presets: The presets the app comes with (declared on the root menu): a MenuItem.Presets item lists them before the presets people save, marked as built in; they cannot be overwritten or deleted. A saved preset whose name matches a built-in one (ignoring case) is hidden.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
item ConsoleMonster.Interactive.MenuPreset required
The item.

Returns

Menu The same instance.
public static Menu Presets(Menu menu, IEnumerable<MenuPreset> items) #

Adds items to Menu.Presets: The presets the app comes with (declared on the root menu): a MenuItem.Presets item lists them before the presets people save, marked as built in; they cannot be overwritten or deleted. A saved preset whose name matches a built-in one (ignoring case) is hidden.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.MenuPreset> required
The items, in order.

Returns

Menu The same instance.
public static Menu Subtitle(Menu menu, string? value) #

Sets Menu.Subtitle: Muted text at the right of the title bar (a version, an environment).

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
value string? required
The value.

Returns

Menu The same instance.

Examples

// C# initializer or property    // C# fluent
menu.Subtitle = value;           Ui.Menu().Subtitle(value);
public static Menu Title(Menu menu, string value) #

Sets Menu.Title: The title.

Parameters

menu ConsoleMonster.Interactive.Menu required
The instance.
value string required
The value.

Returns

Menu The same instance.

Examples

// C# initializer or property    // C# fluent
menu.Title = value;              Ui.Menu().Title(value);