Table of Contents

Class KeyMap

Namespace
MiniTui
Assembly
MiniTui.dll

Key bindings with descriptions, for handling keys and showing hints and help (§8.5).

public sealed class KeyMap
Inheritance
KeyMap
Inherited Members

Examples

var keys = new KeyMap()
    .Add("r", "Refresh", Refresh)
    .Add("j,down", "Down", () => selection.Next(count))
    .Add("q,ctrl+c", "Quit", app.Quit);
app.OnKey(keys.Handle);

Methods

Add(string, string, Action, string?, bool)

Add a binding. keys is one or more comma-separated bindings in the Parse(string) grammar, such as "j,down".

public KeyMap Add(string keys, string description, Action handler, string? group = null, bool showInHints = true)

Parameters

keys string

The bindings.

description string

What the binding does, shown in hints and help.

handler Action

Called when a binding matches.

group string

A heading to list the binding under in HelpLines().

showInHints bool

Whether Hints(int) lists the binding.

Returns

KeyMap

Exceptions

FormatException

keys isn't valid.

Handle(ConsoleKeyInfo)

Run the handler of the first binding that matches key.

public bool Handle(ConsoleKeyInfo key)

Parameters

key ConsoleKeyInfo

Returns

bool

True if a binding matched.

HelpLines()

Help text: one line per binding, " keys description", with the descriptions aligned. Bindings with a group are listed under a line with the group name, after the ungrouped ones.

public IEnumerable<string> HelpLines()

Returns

IEnumerable<string>

Hints(int)

A one-line summary such as "r Refresh q Quit": each binding shown in hints, with its first key. Only whole hints that fit in maxWidth columns are included; if even the first doesn't fit, it's truncated with ….

public string Hints(int maxWidth)

Parameters

maxWidth int

Returns

string