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 extends KeyMap {
  MyKeyMap() {
    shortHelp = [up, down, quit];
    fullHelp = [[up, down], [quit]];
  }

  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');
}

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<KeyBinding>> groups) → String
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