prompt static method

String? prompt(
  1. String message, {
  2. String? defaultVal,
})

Prompts the user for input.

Returns the user's input, or defaultVal if no input is provided. The message is displayed as the prompt text.

Implementation

static String? prompt(String message, {String? defaultVal}) {
  if (defaultVal != null) {
    stdout.write('$bold$message$reset $dim(default: $defaultVal)$reset: ');
  } else {
    stdout.write('$bold$message$reset: ');
  }
  final input = stdin.readLineSync()?.trim();
  if ((input == null || input.isEmpty) && defaultVal != null) {
    return defaultVal;
  }
  return input;
}