processWhile method

Future processWhile({
  1. String promptLabel = 'App> ',
  2. List<String>? initArgs,
})

Implementation

Future processWhile({
  String promptLabel = 'App> ',
  List<String>? initArgs,
}) async {
  if (initArgs != null && initArgs.length > 0) {
    args = initArgs;
    await process();
  }

  final input = stdin.transform(utf8.decoder);
  stdout.write(promptLabel);

  await for (String line in input.transform(LineSplitter())) {
    line = line.trim();
    line = line.replaceAll(RegExp('  '), ' ');
    if (line.isNotEmpty) {
      args = line.split(' ');
      await process();
    }
    stdout.write(promptLabel);
  }
}