run method
int
run({
- required void render(
- FrameContext ctx,
- int value,
- int maxValue
- KeyBindings? extraBindings,
Runs the discrete value prompt.
Implementation
int run({
required void Function(FrameContext ctx, int value, int maxValue) render,
KeyBindings? extraBindings,
}) {
_initState();
_bindings = KeyBindings.horizontalNavigation(
onLeft: () => _value = (_value - 1).clamp(1, maxValue),
onRight: () => _value = (_value + 1).clamp(1, maxValue),
) +
KeyBindings.numbers(
onNumber: (n) {
if (n >= 1 && n <= maxValue) _value = n;
},
max: maxValue,
hintLabel: '1–$maxValue',
hintDescription: 'set exact',
) +
KeyBindings.prompt(onCancel: () => _cancelled = true);
if (extraBindings != null) {
_bindings = _bindings + extraBindings;
}
final frame = FrameView(
title: title,
theme: theme,
bindings: _bindings,
);
void renderFrame(RenderOutput out) {
frame.render(out, (ctx) {
render(ctx, _value, maxValue);
});
}
final runner = PromptRunner(hideCursor: true);
final result = runner.runWithBindings(
render: renderFrame,
bindings: _bindings,
);
return (result == PromptResult.cancelled || _cancelled) ? initial : _value;
}