confirm static method

bool confirm(
  1. String question, {
  2. bool defaultValue = true,
})

Display a confirmation prompt (Y/n)

Implementation

static bool confirm(String question, {bool defaultValue = true}) {
  final defaultHint = defaultValue ? 'Y/n' : 'y/N';
  stdout.write('\x1B[36m?\x1B[0m $question [$defaultHint] ');
  final response = stdin.readLineSync()?.toLowerCase().trim();

  if (response == null || response.isEmpty) {
    return defaultValue;
  }

  return response == 'y' || response == 'yes';
}