SimplePrompt<T> class

SimplePrompt<T> – A lightweight, composable prompt wrapper.

Centralizes the common boilerplate found in basic prompts:

  • State management with cancellation tracking
  • Initial value vs confirmed value handling
  • PromptRunner + FrameView + KeyBindings wiring

Problem it solves: Many prompts repeat the same pattern:

// Before SimplePrompt
bool cancelled = false;
var value = initialValue;
final bindings = KeyBindings.somePreset(onCancel: () => cancelled = true);
final frame = FrameView(...);
void render(RenderOutput out) { frame.render(out, (ctx) { ... }); }
final runner = PromptRunner();
final result = runner.runWithBindings(...);
if (cancelled || result == PromptResult.cancelled) return initialValue;
return value;

After SimplePrompt:

final prompt = SimplePrompt<bool>(
  title: 'Confirm',
  initialValue: true,
  buildBindings: (state) => KeyBindings.togglePrompt(
    onToggle: () => state.value = !state.value,
    onCancel: state.cancel,
  ),
  render: (ctx, state) => renderMyContent(ctx, state.value),
);
return prompt.run(); // Returns initialValue on cancel

Design principles:

  • Composition over inheritance
  • Works alongside existing systems (not a replacement)
  • Separation of concerns (state separate from rendering)
  • DRY: Eliminates repeated cancellation/default value boilerplate

When to use:

  • Simple prompts with a single return value
  • Prompts that don't need list navigation or complex state
  • When you want less boilerplate without creating a new prompt class

When NOT to use:

  • Complex prompts – use SelectableListPrompt, ValuePrompt, etc.
  • Display-only views – use FrameView.show()
Available extensions

Constructors

SimplePrompt({required String title, required T initialValue, required KeyBindings buildBindings(PromptState<T> state), required void render(FrameContext ctx, PromptState<T> state), PromptTheme theme = PromptTheme.dark, bool hideCursor = true})
const

Properties

buildBindings KeyBindings Function(PromptState<T> state)
Builds key bindings given the prompt state.
final
hashCode int
The hash code for this object.
no setterinherited
hideCursor bool
Whether to hide the cursor during the prompt.
final
initialValue → T
Initial value (returned on cancel).
final
render → void Function(FrameContext ctx, PromptState<T> state)
Renders the prompt content.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
theme PromptTheme
Theme for styling.
final
title String
Title displayed in the frame header.
final

Methods

copyWith({String? title, PromptTheme? theme, T? initialValue, KeyBindings buildBindings(PromptState<T> state)?, void render(FrameContext ctx, PromptState<T> state)?, bool? hideCursor}) SimplePrompt<T>

Available on SimplePrompt<T>, provided by the SimplePromptBuilder extension

Creates a copy with modified properties.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run() → T
Runs the prompt and returns the result.
toString() String
A string representation of this object.
inherited

Operators

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