draw method

  1. @override
void draw()
override

Fonction chargée de l'affichage sur le terminal

Implementation

@override
void draw() {
  if (console.windowHeight != height || console.windowWidth != width) {
    height = console.windowHeight;
    width  = console.windowWidth;
    separator = '─'*width;
    _computeSublist();
  }

  displayedElements = 0;
  int availableLines = height;
  if (controller.getFlag("downloadCourse")){
    return;
  }
  console.clearScreen();
  console.setForegroundColor(ConsoleColor.cyan);
  console.writeLine(headerText);
  availableLines -= (headerText.getLineUsed(width) + footerText.getLineUsed(width) + separator.getLineUsed(width));
  console.resetColorAttributes();
  int startIndex = sublistIndex[displayedSubList];
  int endIndex = displayedSubList == (sublistIndex.length)-1 ? optionLength: sublistIndex[displayedSubList+1];
  for (int i = startIndex; i < endIndex; i++) {
    String textToWrite = options[i].downloaded ? '${options[i]} (Téléchargé)' : '${options[i]}';
    String textToDisplay = i == selectedIndex ? '>$textToWrite' : ' $textToWrite';
    if (i == selectedIndex) {
      ConsoleColor dLSelectedColor = options[i].downloaded ? ConsoleColor.green : ConsoleColor.yellow;
      console.setForegroundColor(ConsoleColor.black);
      console.setBackgroundColor(dLSelectedColor);
      console.writeLine(textToDisplay);
      console.resetColorAttributes();
      console.write("\n");
    } else {
      console.writeLine(textToDisplay);
      console.resetColorAttributes();
      console.write("\n");
    }
    availableLines -= textToDisplay.getLineUsed(console.windowWidth) + 1;
    displayedElements++;
    if (availableLines < 5){
      endIndex = i;
      // No more lines available to display text on terminal, so change displayEndIndex to this one
    }
  }
  //final linesToFill = realTerminalHeight - (MAX_DISPLAY_LINES*2)-2; // -2 pour marge et footer
  for (int i = 0; i < availableLines-1; i++) {
    console.writeLine('');
  }
  console.setForegroundColor(ConsoleColor.brightCyan);
  console.writeLine(separator); // ligne de séparation
  console.setForegroundColor(ConsoleColor.brightCyan);
  console.writeLine(footerText);
}