HelpModel class
A help view widget for displaying key bindings.
The help view can display key bindings in two modes:
- Short: A single line showing the most important bindings
- Full: Multiple columns showing all bindings grouped
Example
class MyKeyMap implements KeyMap {
final up = KeyBinding.withHelp(['up', 'k'], '↑/k', 'move up');
final down = KeyBinding.withHelp(['down', 'j'], '↓/j', 'move down');
final quit = KeyBinding.withHelp(['q'], 'q', 'quit');
@override
List<KeyBinding> shortHelp() => [up, down, quit];
@override
List<List<KeyBinding>> fullHelp() => [[up, down], [quit]];
}
class MyModel implements Model {
final HelpModel help;
final MyKeyMap keyMap;
MyModel({HelpModel? help, MyKeyMap? keyMap})
: help = help ?? HelpModel(),
keyMap = keyMap ?? MyKeyMap();
@override
(Model, Cmd?) update(Msg msg) {
// Toggle help with ?
if (msg is KeyMsg && msg.key.matchesSingle(CommonKeyBindings.help)) {
return (
MyModel(help: help.copyWith(showAll: !help.showAll), keyMap: keyMap),
null,
);
}
return (this, null);
}
@override
String view() => '...\n${help.view(keyMap)}';
}
Constructors
- HelpModel({int width = 0, bool showAll = false, HelpStyles? styles})
- Creates a new help model.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showAll → bool
-
Whether to show the full help view.
final
- styles → HelpStyles
-
Styles for the help view.
final
- width → int
-
Maximum width for the help view. 0 means no limit.
final
Methods
-
copyWith(
{int? width, bool? showAll, HelpStyles? styles}) → HelpModel - Creates a copy with the given fields replaced.
-
fullHelpView(
List< List< groups) → StringKeyBinding> > - Renders a full help view from grouped key bindings.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shortHelpView(
List< KeyBinding> bindings) → String - Renders a short help view from a list of key bindings.
-
toString(
) → String -
A string representation of this object.
override
-
view(
KeyMap keyMap) → String - Renders the help view using the given key map.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited