selectLogPatterns method

List<RegExp> selectLogPatterns()

Selects and returns a list of regular expression patterns used for log removal.

This method is responsible for providing the patterns that will be used to identify and remove log entries from the application logs.

Returns: A list of RegExp objects representing the log patterns to be removed.

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 šŸ”'), // Tambahkan opsi untuk memasukkan nama log custom
    ).interact();

    final selectedPatterns = <RegExp>[];
    for (final index in multiSelect) {
      if (index < defaultPatterns.length) {
        selectedPatterns
            .add(defaultPatterns[index].pattern); // Tambahkan pola default
        console.setForegroundColor(ConsoleColor.green);
        print('āœ… Added: ${defaultPatterns[index].name}');
      } else {
        final customPattern = _getCustomPattern(); // Dapatkan pola custom
        selectedPatterns.add(customPattern); // Tambahkan pola custom
      }
    }

    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; // Kembalikan daftar pola yang dipilih
    }
  }
}