PromptRunner class

A centralized runner for interactive terminal prompts.

Composes TerminalSession + RenderOutput + key handling to provide a complete solution for interactive prompts.

Key feature: Never clears the entire terminal. Only clears lines written by the prompt/view itself, preserving any existing terminal content.

Usage:

final runner = PromptRunner();
final result = runner.run(
  render: (out) {
    out.writeln('My prompt content');
    out.writeln('More content');
  },
  onKey: (event) {
    if (event.type == KeyEventType.enter) return PromptResult.confirmed;
    if (event.type == KeyEventType.esc) return PromptResult.cancelled;
    return null; // continue loop
  },
);
Available extensions

Constructors

PromptRunner({bool hideCursor = true, EndBehavior endBehavior = EndBehavior.clear, void onBeforeCleanup()?, void onAfterCleanup()?})

Properties

endBehavior → EndBehavior
Controls what happens when the prompt ends.
final
hashCode → int
The hash code for this object.
no setterinherited
hideCursor → bool
Whether to hide the terminal cursor during the prompt.
final
onAfterCleanup → void Function()?
Optional callback invoked after cleanup completes.
final
onBeforeCleanup → void Function()?
Optional callback invoked before cleanup (e.g., for final styling).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run({required void render(RenderOutput out), required PromptResult? onKey(KeyEvent event)}) → PromptResult
Runs the prompt loop synchronously.
runCustom<T>(T body(RenderOutput out)) → T
Runs custom logic within a managed terminal session.
runWithBindings({required void render(RenderOutput out), required KeyBindings bindings}) → PromptResult
Runs the prompt loop using a KeyBindings instance.
runWithFrame({required FrameView frame, required void content(FrameContext ctx), required KeyBindings bindings}) → PromptResult

Available on PromptRunner, provided by the PromptRunnerFrameExtension extension

Runs a prompt with FrameView-based rendering.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

toPromptResult(KeyActionResult result) → PromptResult?
Converts the result to PromptRunner's PromptResult.