function select_item(items) {
  if (!items || !items.length) {
    return -1;
  }

  const MAX_ITEMS = config["select_count"],
    MAX_PAGE_INDEX = Math.ceil(items.length / MAX_ITEMS) - 1;

  let page_index = 0;
  while (true) {
    const PAGE_ITEMS = [];
    let index_prev = -1,
      index_next = -1;
    if (page_index > 0) {
      PAGE_ITEMS.push(`(PREVIOUS ${MAX_ITEMS} items)`);
      index_prev = PAGE_ITEMS.length - 1;
    }
    Array.prototype.push.apply(
      PAGE_ITEMS,
      items.slice(page_index * MAX_ITEMS, (page_index + 1) * MAX_ITEMS)
    );
    if (page_index < MAX_PAGE_INDEX) {
      PAGE_ITEMS.push(
        `(NEXT ${
          page_index < MAX_PAGE_INDEX - 1
            ? MAX_ITEMS
            : items.length - MAX_ITEMS * (page_index + 1)
        } item(s))`
      );
      index_next = PAGE_ITEMS.length - 1;
    }

    //console.log('\x1B[2J');
    clear_screen();
    rl.pause();
    const index = rl_sync.keyInSelect(PAGE_ITEMS);
    rl.resume();
    if (index_prev !== -1 && index === index_prev) {
      page_index--;
    } else if (index_next !== -1 && index === index_next) {
      page_index++;
    } else {
      return index === -1
        ? index
        : index + page_index * MAX_ITEMS - (index_prev === -1 ? 0 : 1);
    }
  }
}
// Select an item from a list and return the index
Select an item from a list and return the index
Select an item from a list and return the index
function select_item(items) {
  if (!items || !items.length) {
    return -1;
  }
  const MAX_ITEMS = config["select_count"],
    MAX_PAGE_INDEX = Math.ceil(items.length / MAX_ITEMS) - 1;
  let page_index = 0;
  while (true) {
    const PAGE_ITEMS = [];
    let index_prev = -1,
      index_next = -1;
    if (page_index > 0) {
      PAGE_ITEMS.push(`(PREVIOUS ${MAX_ITEMS} items)`);
      index_prev = PAGE_ITEMS.length - 1;
    }
    Array.prototype.push.apply(
      PAGE_ITEMS,
      items.slice(page_index * MAX_ITEMS, (page_index + 1) * MAX_ITEMS)
    );
    if (page_index < MAX_PAGE_INDEX) {
      PAGE_ITEMS.push(
        `(NEXT ${
          page_index < MAX_PAGE_INDEX - 1
            ? MAX_ITEMS
            : items.length - MAX_ITEMS * (page_index + 1)
        } item(s))`
      );
      index_next = PAGE_ITEMS.length - 1;
    }
    clear_screen();
    rl.pause();
    const index = rl_sync.keyInSelect(PAGE_ITEMS);
    rl.resume();
    if (index_prev !== -1 && index === index_prev) {
      page_index--;
    } else if (index_next !== -1 && index === index_next) {
      page_index++;
    } else {
      return index === -1
        ? index
        : index + page_index * MAX_ITEMS - (index_prev === -1 ? 0 : 1);
    }
  }
}
function select_item ( items ) { if ( ! items || ! items . length ) { return - 1 ; } const MAX_ITEMS = config [ "select_count" ] , MAX_PAGE_INDEX = Math . ceil ( items . length / MAX_ITEMS ) - 1 ; let page_index = 0 ; while ( true ) { const PAGE_ITEMS = [ ] ; let index_prev = - 1 , index_next = - 1 ; if ( page_index > 0 ) { PAGE_ITEMS . push ( ` ${ MAX_ITEMS } ` ) ; index_prev = PAGE_ITEMS . length - 1 ; } Array . prototype . push . apply ( PAGE_ITEMS , items . slice ( page_index * MAX_ITEMS , ( page_index + 1 ) * MAX_ITEMS ) ) ; if ( page_index < MAX_PAGE_INDEX ) { PAGE_ITEMS . push ( ` ${ page_index < MAX_PAGE_INDEX - 1 ? MAX_ITEMS : items . length - MAX_ITEMS * ( page_index + 1 ) } ` ) ; index_next = PAGE_ITEMS . length - 1 ; } clear_screen ( ) ; rl . pause ( ) ; const index = rl_sync . keyInSelect ( PAGE_ITEMS ) ; rl . resume ( ) ; if ( index_prev !== - 1 && index === index_prev ) { page_index -- ; } else if ( index_next !== - 1 && index === index_next ) { page_index ++ ; } else { return index === - 1 ? index : index + page_index * MAX_ITEMS - ( index_prev === - 1 ? 0 : 1 ) ; } } }
Select an item from a list and return the index
Select an item from a list and return the index
//console.log('\x1B[2J');