Skip to content
ConsoleMonster
Class

CommanderCommand

ConsoleMonster.Apps.Commander

Namespace
ConsoleMonster.Apps.Commander
Assembly
ConsoleMonster
Modifiers
sealed

One Commander command as data: a stable key, a label, its keys (the first is primary, the rest are alternatives for terminals that swallow F-keys), an optional key-bar slot, when it's available and what it does. The palette, key bar, help and key routing all come from the same CommanderCommands.

Inheritance

  • object
  • CommanderCommand

Usage

Explore 6 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 1

Constructors

public CommanderCommand(string key, string label, Action<CommanderContext> execute, params KeyChord[] keys) #

Creates a command.

Parameters

key string required
The stable key, such as copy.
label string required
What it does, for the palette and help.
execute System.Action<ConsoleMonster.Apps.Commander.CommanderContext> required
The action, called on the app thread when the command is available.
keys ConsoleMonster.Input.KeyChord[] required
Its keys, primary first; none for palette-only commands.

Methods

public bool IsAvailable(CommanderContext context) #

Whether the command can run now; unavailable commands do nothing and show dimmed.

Parameters

context ConsoleMonster.Apps.Commander.CommanderContext required
The context.

Returns

bool True when available.
public bool Matches(InputEvent input) #

Whether a key event is one of this command's keys.

Parameters

input ConsoleMonster.Input.InputEvent required
The event.

Returns

bool True on a match.
public KeyBinding ToKeyBinding(CommanderContext context) #

The command as a key binding, for the app host's routing, footer and key map.

Parameters

context ConsoleMonster.Apps.Commander.CommanderContext required
The context its action runs in.

Returns

KeyBinding The binding; its action does nothing while the command is unavailable.
public override string ToString() #

Returns a string that represents the current object.

Returns

string A string that represents the current object.
public bool TryExecute(CommanderContext context) #

Runs the command when it's available.

Parameters

context ConsoleMonster.Apps.Commander.CommanderContext required
The context.

Returns

bool Whether it ran.

Properties

public string Key { get; } #

The stable key.

public string Label { get; } #

What it does.

public Action<CommanderContext> Execute { get; } #

The action.

public IReadOnlyList<KeyChord> Keys { get; } #

All keys, primary first.

public KeyChord? Gesture { get; } #

The primary key, or null for a palette-only command.

public IReadOnlyList<KeyChord> Alternatives { get; } #

The alternative keys.

public int FunctionKey { get; set; } #

The key-bar slot from 1 to 10, or 0 when it has none.

public string? BarLabel { get; set; } #

The short key-bar label, such as Mkdir; the label when null.

public string Group { get; set; } #

The help and palette heading.

public bool RequiresHost { get; set; } #

Whether the command needs ICommanderHost.Supports to be true.

public Func<CommanderContext, bool>? Available { get; set; } #

When the command can run; always when null.