Skip to content
ConsoleMonster
Class

KeyBinding

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Modifiers
sealed

A key binding: the keys, what they do and the words that describe them. Footers and the key map are generated from the active bindings, so what the screen says is always what the keys do.

Inheritance

  • object
  • KeyBinding

Usage

Explore 99 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 70

Constructors

public KeyBinding(string label, Action action, params KeyChord[] chords) #

Creates a binding.

Parameters

label string required
What the keys do ("select", "toggle").
action System.Action required
The action.
chords ConsoleMonster.Input.KeyChord[] required
The keys.

Methods

public static KeyBinding Create(string keys, string label, Action action) #

Creates a binding from key names ("Ctrl+K", ":").

Parameters

keys string required
The keys, as KeyChord.Parse accepts them.
label string required
What the keys do.
action System.Action required
The action.

Returns

KeyBinding The binding.
public string DisplayKeys() #

The key text as shown in footers: lower-case names (enter, ctrl+a), characters as typed.

Returns

string The text.
public bool Matches(InputEvent input) #

Whether an event triggers this binding.

Parameters

input ConsoleMonster.Input.InputEvent required
The event.

Returns

bool True on a match.
public static KeyBinding Numbered(string label, Func<int> count, Action<int> open) #

Opens numbered items: 1-9 open at once, and with ten or more items the digits build the number (1 then 2 opens 12). A digit that could still start a larger number waits; Enter opens it, Escape or any other key forgets it. The footer shows 1-N, or the digits typed so far.

Parameters

label string required
What opening does ("open").
count System.Func<int> required
The current number of items; read on every key.
open System.Action<int> required
Opens the one-based item number.

Returns

KeyBinding The binding.

Properties

public IReadOnlyList<KeyChord> Chords { get; } #

The keys.

public string Label { get; } #

What the keys do.

public Action Action { get; } #

The action.

public string? KeyText { get; set; } #

How the keys are shown (for example ↑↓); null shows the first chord.

public Func<bool>? Available { get; set; } #
Fluent("AvailableWhen")

Whether the binding can run now; null means always. An unavailable binding stays in the footer dimmed and its keys do nothing, so they never fall through to another binding the footer does not show.

public string Group { get; set; } #

The heading the binding is listed under in the key map.

public int Order { get; set; } #

Footer priority: lower values are shown first and dropped last when space runs out.

public bool InFooter { get; set; } #

Whether the footer shows the binding (the key map always lists it).

Extension Methods

public static KeyBinding AvailableWhen(KeyBinding keyBinding, Func<bool>? value) #

Sets KeyBinding.Available: Whether the binding can run now; null means always. An unavailable binding stays in the footer dimmed and its keys do nothing, so they never fall through to another binding the footer does not show.

Parameters

keyBinding ConsoleMonster.Interactive.KeyBinding required
The instance.
value System.Func<bool>? required
The callback.

Returns

KeyBinding The same instance.

Examples

// C# initializer or property    // C# fluent
keyBinding.Available = value;    keyBinding.AvailableWhen(value);
public static KeyBinding Group(KeyBinding keyBinding, string value) #

Sets KeyBinding.Group: The heading the binding is listed under in the key map.

Parameters

keyBinding ConsoleMonster.Interactive.KeyBinding required
The instance.
value string required
The value.

Returns

KeyBinding The same instance.

Examples

// C# initializer or property    // C# fluent
keyBinding.Group = value;        keyBinding.Group(value);
public static KeyBinding InFooter(KeyBinding keyBinding, bool value = true) #

Sets KeyBinding.InFooter: Whether the footer shows the binding (the key map always lists it).

Parameters

keyBinding ConsoleMonster.Interactive.KeyBinding required
The instance.
value bool = true optional
The value; true when omitted.

Returns

KeyBinding The same instance.

Examples

// C# initializer or property    // C# fluent
keyBinding.InFooter = value;     keyBinding.InFooter(value);
public static KeyBinding KeyText(KeyBinding keyBinding, string? value) #

Sets KeyBinding.KeyText: How the keys are shown (for example ↑↓); null shows the first chord.

Parameters

keyBinding ConsoleMonster.Interactive.KeyBinding required
The instance.
value string? required
The value.

Returns

KeyBinding The same instance.

Examples

// C# initializer or property    // C# fluent
keyBinding.KeyText = value;      keyBinding.KeyText(value);
public static KeyBinding Order(KeyBinding keyBinding, int value) #

Sets KeyBinding.Order: Footer priority: lower values are shown first and dropped last when space runs out.

Parameters

keyBinding ConsoleMonster.Interactive.KeyBinding required
The instance.
value int required
The value.

Returns

KeyBinding The same instance.

Examples

// C# initializer or property    // C# fluent
keyBinding.Order = value;        keyBinding.Order(value);