code: public CursorLocation locate(int index, int width) {
          // Upper lines location has been lost.
          if (isLocationInvalidated()) {
              return null;
          }
          int cumulated = 0;
  
          List<Integer> allLines = new ArrayList<>();
          allLines.addAll(linesSize);
          allLines.add(buffer.length());
          allLines.add(buffer.prompt().getLength());
          int lineIndex = 0;
          for (int i = 0; i < allLines.size(); i++) {
              int cmdSize = allLines.get(i++);
              int promptSize = allLines.get(i);
              lineIndex += 1;
              if (cumulated + cmdSize > index) {
                  int part = index - cumulated;
                  int col = (part + promptSize) % width;
                  // if the part + prompt is longer than width, then
                  // the row is in a lower line.
                  lineIndex += (promptSize + part) / width;
                  return new CursorLocation(lineIndex - 1, col);
              }
              cumulated += cmdSize;
              // Each line could be wrapped if longer than width.
              lineIndex += (cmdSize + promptSize) / width;
          }
          // we are on the last line at the last character.
          if (cumulated == index) {
              int cmdSize = allLines.get(allLines.size() - 2);
              int promptSize = allLines.get(allLines.size() - 1);
              int col = (cmdSize + promptSize) % width;
              return new CursorLocation(lineIndex - 1, col);
          } else {
              return null;
          }
      }
docs: The core logic of the locator. Map a command index onto an absolute
  COL/ROW cursor location.
  
  @param index The commnd index.
  @param width The terminal width.
  @return