promptSync method

String promptSync(
  1. String? message, {
  2. Object? defaultValue,
  3. bool hidden = false,
})

Like prompt, but blocks and returns the answer, as mason_logger's prompt does. For code that is already synchronous; see promptInputSync for what sync prompts can't do.

Implementation

String promptSync(
  String? message, {
  Object? defaultValue,
  bool hidden = false,
}) {
  final fallback = defaultValue == null ? '' : '$defaultValue';
  final label = fallback.isEmpty
      ? '$message'
      : '$message ${_paint(_out, _darkGray, '($fallback)')}';
  final answer = _askSync(
      'promptSync',
      () => promptInputSync(label,
          hidden: hidden, defaultValue: fallback, options: _options));
  final value = hidden ? answer : answer?.trim();
  return value == null || value.isEmpty ? fallback : value;
}