版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

22 строки
721 B

  1. 'use strict';
  2. /**
  3. * Determine what entries should be displayed on the screen, based on the
  4. * currently selected index and the maximum visible. Used in list-based
  5. * prompts like `select` and `multiselect`.
  6. *
  7. * @param {number} cursor the currently selected entry
  8. * @param {number} total the total entries available to display
  9. * @param {number} [maxVisible] the number of entries that can be displayed
  10. */
  11. module.exports = (cursor, total, maxVisible) => {
  12. maxVisible = maxVisible || total;
  13. let startIndex = Math.min(total- maxVisible, cursor - Math.floor(maxVisible / 2));
  14. if (startIndex < 0) startIndex = 0;
  15. let endIndex = Math.min(startIndex + maxVisible, total);
  16. return { startIndex, endIndex };
  17. };