getBool function
Presents a yes/no prompt to the user.
If appendYesNo
is true
, then a (y/n)
, (Y/n)
or (y/N)
is
appended to the message
, depending on its value.
color
, inputColor
, conceal
, and chevron
are forwarded to get.
Implementation
bool getBool(String message,
{bool defaultsTo = false,
bool appendYesNo = true,
bool color = true,
bool chevron = true,
bool conceal = false,
@deprecated bool colon = true,
AnsiCode inputColor = cyan}) {
if (appendYesNo) {
message +=
// ignore: unnecessary_null_comparison
defaultsTo == null ? ' (y/n)' : (defaultsTo ? ' (Y/n)' : ' (y/N)');
}
var result = get(
message,
color: color,
inputColor: inputColor,
conceal: conceal,
chevron: chevron && colon,
validate: (s) {
s = s.trim().toLowerCase();
return (s.isEmpty) || s.startsWith('y') || s.startsWith('n');
},
);
result = result.toLowerCase();
if (result.isEmpty) {
return defaultsTo;
} else if (result == 'y') return true;
return false;
}