runWithBindings method

PromptResult runWithBindings({
  1. required void render(
    1. RenderOutput out
    ),
  2. required KeyBindings bindings,
})

Runs the prompt loop using a KeyBindings instance.

This is the recommended way to use PromptRunner with the KeyBindings system. It automatically handles the mapping from KeyActionResult to PromptResult.

Example:

final bindings = KeyBindings.togglePrompt(
  onToggle: () => selectedYes = !selectedYes,
);

final result = runner.runWithBindings(
  render: (out) => renderPrompt(out),
  bindings: bindings,
);

Implementation

PromptResult runWithBindings({
  required void Function(RenderOutput out) render,
  required KeyBindings bindings,
}) {
  return run(
    render: render,
    onKey: (event) {
      final result = bindings.handle(event);
      return toPromptResult(result);
    },
  );
}