ask method

Future<String> ask(
  1. String message, {
  2. String? defaultValue,
  3. String? placeholder,
  4. bool obscure = false,
  5. String? validate(
    1. String value
    )?,
})

Asks the user for a free-form string answer.

validate returns null to accept, or an error message to retry. Returns the submitted value, or defaultValue when the user submits an empty line and a defaultValue is provided.

Implementation

Future<String> ask(
  String message, {
  String? defaultValue,
  String? placeholder,
  bool obscure = false,
  String? Function(String value)? validate,
}) {
  final state = InputState();
  return runOneShot<String>(
    (ctx, submit) => ctx.draw(
      Input(
        id: Key.symbol(#__inline_ask),
        message: message,
        state: state,
        defaultValue: defaultValue,
        placeholder: placeholder,
        obscure: obscure,
        validate: validate,
        onSubmit: submit,
      ),
      Rect(ctx.area.x, ctx.area.y, ctx.area.width,
          state.error != null ? 2 : 1),
    ),
    theme: _theme,
    terminal: _terminal(),
    allowNonInteractive: _allowNonInteractive,
  );
}