confirmTUI function

bool confirmTUI(
  1. String message, {
  2. bool defaultValue = false,
  3. bool? skip,
})

TUI-enhanced confirmation prompt.

Uses mason_logger for yes/no confirmations with better UX. Falls back to basic stdin when TUI is disabled.

message The confirmation message to display. defaultValue The default value if user just presses Enter. skip A boolean indicating whether to skip the prompt.

Returns true if user confirms, false otherwise.

Implementation

bool confirmTUI(String message, {bool defaultValue = false, bool? skip}) {
  if (skip == true) {
    logger.i('$message >>| Skipping with ($defaultValue)...');
    return defaultValue;
  }

  if (!isTUIEnabled()) {
    // Fallback to basic confirmation
    final answer = promptUser(
      message,
      defaultValue ? 'y' : 'n',
      validator: (input) {
        final normalized = input.toLowerCase();
        return normalized == 'y' ||
            normalized == 'n' ||
            normalized == 'yes' ||
            normalized == 'no';
      },
    );
    return answer.toLowerCase() == 'y' || answer.toLowerCase() == 'yes';
  }

  return confirmWithTUI(message, defaultValue: defaultValue);
}