promptUserTUI function
TUI-enhanced version of promptUser with better interactive experience.
Uses mason_logger for enhanced prompting when TUI is enabled. Falls back to basic promptUser when TUI is disabled or --skipAll is used.
promptMessage The message to display to the user.
defaultValue The default value to use if the user provides no input.
validator An optional function to validate the user's input.
skip A boolean indicating whether to skip the prompt.
skipValue An optional value to return if skip is true.
Returns the validated user input or the default/skip value.
Implementation
String promptUserTUI(
String promptMessage,
String defaultValue, {
bool Function(String)? validator,
bool? skip,
String? skipValue,
}) {
// Use basic prompt if skipping or TUI is disabled
if (skip == true || !isTUIEnabled()) {
return promptUser(
promptMessage,
defaultValue,
validator: validator,
skip: skip,
skipValue: skipValue,
);
}
// Use TUI-enhanced prompt
while (true) {
final answer = promptWithTUI(
promptMessage,
defaultValue: defaultValue.isNotEmpty ? defaultValue : null,
);
final value = answer.isEmpty ? defaultValue : answer;
// Validate if validator is provided
if (validator != null && !validator(value)) {
errorMessage('Invalid input. Please try again.');
continue;
}
return value;
}
}