displayOptions method

void displayOptions()

Implementation

void displayOptions() {
  setOptions();
  while (true) {
    final key = console.readKey();
    if (key.controlChar == ControlCharacter.arrowUp) {
      console.clearScreen();
      if (selectedIndex > 0) {
        selectedIndex--;
        setOptions();
      }
    } else if (key.controlChar == ControlCharacter.arrowDown) {
      console.clearScreen();
      if (selectedIndex < options.length - 1) {
        selectedIndex++;
        setOptions();
      }
    } else if (key.controlChar == ControlCharacter.enter) {
      console.clearScreen();
      onSelectedOptions(options[selectedIndex]);
      break;
    } else if (key.controlChar == ControlCharacter.ctrlC) {
      console.clearScreen();
      console.writeLine('Exited.');
      exit(0);
    }
  }
}