chooseOne<T> method

  1. @override
T chooseOne<T>(
  1. String message, {
  2. required List<T> choices,
  3. T? defaultValue,
  4. String display(
    1. T
    )?,
})
override

Prompts user to select one choice from choices.

Implementation

@override
T chooseOne<T>(String message,
    {required List<T> choices,
    T? defaultValue,
    String Function(T)? display}) {
  if (_isJsonOutput) return defaultValue ?? choices.first;

  // Hack to prevent mason_logger from breaking when choices cause terminal scrolling.
  // We pre-allocate the lines to force scrolling before saving the cursor.
  final linesNeeded = choices.length + 1;
  io.stdout.write('\n' * linesNeeded);
  io.stdout.write('\x1B[${linesNeeded}A');

  return _logger.chooseOne<T>(message,
      choices: choices, defaultValue: defaultValue, display: display);
}