KeyBinding class
A key binding that maps keys to actions with optional help text.
Key bindings are the foundation of TUI keyboard navigation. They allow you to define which keys trigger which actions, and provide help text for user documentation.
Example
final upBinding = KeyBinding(
keys: ['up', 'k'],
help: Help(key: '↑/k', desc: 'move up'),
);
final quitBinding = KeyBinding(
keys: ['q', 'ctrl+c'],
help: Help(key: 'q', desc: 'quit'),
);
Constructors
-
KeyBinding({List<
String> ? keys, Help? help, bool disabled = false, Cmd? handler()?, void action()?}) - Creates a new key binding.
-
KeyBinding.withHelp(List<
String> keys, String keyText, String desc) -
Creates a key binding with keys and help text.
factory
-
KeyBinding.withKeys(List<
String> keys) -
Creates a key binding with the given keys.
factory
Properties
- action → void Function()?
-
Widget-level callback invoked when this binding is intercepted.
final
- enabled ↔ bool
-
Whether this binding is enabled.
getter/setter pair
- handler → Cmd? Function()?
-
Optional handler invoked when this binding is activated.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- help ↔ Help
-
The help information for this binding.
getter/setter pair
-
keys
↔ List<
String> -
The keys that trigger this binding.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
activate(
KeyMsg msg) → Cmd? -
Attempts to activate this binding for
msg. -
disable(
) → void - Disables this binding.
-
enable(
) → void - Enables this binding.
-
matches(
KeyMsg msg) → bool -
Returns
trueif this binding is enabled andmsgmatches its keys. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setHelp(
String key, String desc) → void - Sets the help text for this binding.
-
toString(
) → String -
A string representation of this object.
inherited
-
unbind(
) → void - Removes the keys and help from this binding, effectively nullifying it.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited