runCustom method

List<T> runCustom({
  1. required void renderContent(
    1. FrameContext ctx
    ),
  2. KeyBindings? extraBindings,
})

Runs with custom full-render control (for complex grids like ChoiceMap).

renderContent receives the FrameContext for complete control.

Implementation

List<T> runCustom({
  required void Function(FrameContext ctx) renderContent,
  KeyBindings? extraBindings,
}) {
  if (items.isEmpty) return [];

  _initState();

  if (extraBindings != null) {
    _bindings = _bindings + extraBindings;
  }

  final frame = FrameView(
    title: title,
    theme: theme,
    bindings: _bindings,
  );

  void render(RenderOutput out) {
    if (columns <= 0) {
      _recomputeLayout();
      _grid.columns = _computedColumns;
    }

    frame.render(out, renderContent);
  }

  final runner = PromptRunner(hideCursor: true);
  final result = runner.runWithBindings(
    render: render,
    bindings: _bindings,
  );

  if (_cancelled || result == PromptResult.cancelled) {
    return [];
  }

  return _selection.getSelectedMany(
    items,
    fallbackIndex: _grid.focusedIndex,
  );
}