selectLogPatterns method
Prompts the user to select log patterns to remove from a list of default patterns or to input a custom log pattern. The user can toggle selections using the space key.
The method will continue to prompt the user until at least one log pattern is selected.
Returns a list of selected RegExp patterns.
- If a default pattern is selected, it is added to the list of selected patterns.
- If the custom log name option is selected, the user is prompted to input a custom pattern, which is then added to the list of selected patterns.
The method provides visual feedback in the console using different colors:
- Blue for the initial prompt
- Green for confirming a pattern has been added
- Red for indicating that no patterns were selected
- Yellow for indicating that the selection process will restart
Implementation
List<RegExp> selectLogPatterns() {
while (true) {
console.setForegroundColor(ConsoleColor.brightBlue);
print('\nš§ Choose log patterns to remove:');
final multiSelect = MultiSelect(
prompt:
'⨠Select the log patterns you want to remove: (use space to toggle)',
options: defaultPatterns.map((pattern) => pattern.name).toList()
..add('Custom Log Name š'),
).interact();
final selectedPatterns = <RegExp>[];
for (final index in multiSelect) {
if (index < defaultPatterns.length) {
selectedPatterns.add(defaultPatterns[index].pattern!);
console.setForegroundColor(ConsoleColor.green);
print('ā
Added: ${defaultPatterns[index].name}');
} else {
final customPattern = _getCustomPattern();
selectedPatterns.add(customPattern);
}
}
if (selectedPatterns.isEmpty) {
console.setForegroundColor(ConsoleColor.red);
print('\nā You must select at least one log pattern!');
console.setForegroundColor(ConsoleColor.yellow);
print('š Returning to log pattern selection...\n');
} else {
console.resetColorAttributes();
return selectedPatterns;
}
}
}