run method

  1. @override
Future<String?> run(
  1. CliIO io,
  2. CliTheme theme
)
override

Implementation

@override
Future<String?> run(clix.CliIO io, clix.CliTheme theme) async {
  if (options.isEmpty) return null;
  var visible = options;
  while (true) {
    for (var index = 0; index < visible.length; index++) {
      io.writeln('${index + 1}. ${visible[index]}');
    }
    final answer = await ClixInput(
      prompt: '$prompt (number, search text, or blank to cancel)',
    ).interact(io, theme);
    if (answer.isEmpty) return null;
    final number = int.tryParse(answer);
    if (number != null) {
      if (number >= 1 && number <= visible.length) {
        return visible[number - 1];
      }
      io.writeln(theme.error('Enter a number from 1 to ${visible.length}.'));
      continue;
    }
    final matches = options
        .where(
          (option) => option.toLowerCase().contains(answer.toLowerCase()),
        )
        .toList();
    if (matches.isEmpty) {
      io.writeln(theme.error('No options match.'));
    } else {
      visible = matches;
    }
  }
}