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
keysstringThe bindings.
descriptionstringWhat the binding does, shown in hints and help.
handlerActionCalled when a binding matches.
groupstringA heading to list the binding under in HelpLines().
showInHintsboolWhether Hints(int) lists the binding.
Returns
Exceptions
- FormatException
keysisn't valid.
Handle(ConsoleKeyInfo)
Run the handler of the first binding that matches key.
public bool Handle(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfo
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
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
maxWidthint