Skip to content

Commit 7dfdb3c

Browse files
committed
feat: add character matching in switch component
1 parent e3149e9 commit 7dfdb3c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/src/components/switch.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Switch with Tools implements Component<Result<bool>> {
1818
String? errorMessage;
1919
late final String exitMessage;
2020

21-
final allowedYesValues = ['yes', 'y'];
22-
final allowedNoValues = ['no', 'n'];
21+
final List<String> allowedYesValues = ['yes', 'y'];
22+
final List<String> allowedNoValues = ['no', 'n'];
2323

2424
final _completer = Completer<Result<bool>>();
2525

@@ -32,12 +32,15 @@ class Switch with Tools implements Component<Result<bool>> {
3232
required this.answer,
3333
this.defaultValue,
3434
String? exitMessage,
35+
List<String>? allowedYesValues,
36+
List<String>? allowedNoValues,
3537
}) {
36-
this.exitMessage =
37-
exitMessage ?? '${AsciiColors.red('✘')} Operation canceled by user';
38+
this.exitMessage = exitMessage ?? '${AsciiColors.red('✘')} Operation canceled by user';
3839
if (defaultValue != null) {
3940
value = defaultValue!;
4041
}
42+
this.allowedNoValues.addAll(allowedNoValues ?? []);
43+
this.allowedYesValues.addAll(allowedYesValues ?? []);
4144
}
4245

4346
/// Handles the switch component and returns a [Future] that completes with the result of the switch.

0 commit comments

Comments
 (0)