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 {
  var current = startDirectory.absolute;
  while (true) {
    final children =
        (await current.list().toList()).whereType<Directory>().toList()
          ..sort((left, right) => _label(left).compareTo(_label(right)));
    io.writeln('Current directory: ${current.path}');
    final selection = await ClixSelector(
      prompt: prompt,
      options: [
        'Use this directory',
        'Go to parent',
        for (final child in children) _label(child),
      ],
    ).interact(io, theme);
    if (selection == null) return null;
    if (selection == 'Use this directory') return current.path;
    current = selection == 'Go to parent'
        ? current.parent
        : children.firstWhere((child) => _label(child) == selection);
  }
}