promptConfirm static method
Prompts the user for a Yes/No question.
Implementation
static bool promptConfirm(String message, {bool defaultValue = true}) {
final defaultSuffix = defaultValue
? ' ${Logger.gray}(Y/n)${Logger.reset}'
: ' ${Logger.gray}(y/N)${Logger.reset}';
while (true) {
stdout.write('${Logger.green}?${Logger.reset} ${Logger.bold}$message${Logger.reset}$defaultSuffix: ');
final input = stdin.readLineSync(encoding: utf8)?.trim().toLowerCase() ?? '';
if (input.isEmpty) {
return defaultValue;
}
if (input == 'y' || input == 'yes') {
return true;
}
if (input == 'n' || input == 'no') {
return false;
}
Logger.warning('Please enter "y" or "n".');
}
}