runCustom<T> method
Runs custom logic within a managed terminal session.
This gives you full control over the render/input flow while still benefiting from centralized terminal management and RenderOutput for partial clearing.
Use this for prompts or views that need:
- Entry/exit styling
- Custom render timing
- Non-standard input loops
Example:
final runner = PromptRunner();
final value = runner.runCustom((out) {
// Render with entry styling
// Main input loop
while (true) {
final ev = KeyEventReader.read();
if (ev.type == KeyEventType.enter) break;
// handle keys...
out.clear();
renderSlider(out);
}
// Render with exit styling
out.clear();
return finalValue;
});
Implementation
T runCustom<T>(T Function(RenderOutput out) body) {
final session = _createSession();
final output = RenderOutput();
session.start();
try {
return body(output);
} finally {
onBeforeCleanup?.call();
session.end();
onAfterCleanup?.call();
// Optionally clear our final output
if (endBehavior.clearOnEnd) {
output.clear();
}
}
}