Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

terminal-paginator

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

terminal-paginator - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

49

index.js
'use strict';
var debug = require('debug')('terminal-paginator');
var extend = require('extend-shallow');
var log = require('log-utils');

@@ -21,5 +22,16 @@

Paginator.prototype.paginate = function(output, selected, limit) {
limit = limit || this.options.limit || 7;
/**
* Paginate the given `output` string and update the cursor position.
*
* @param {String} `output`
* @param {Number} `pos`
* @param {Object} `options`
* @return {String}
* @api public
*/
Paginator.prototype.paginate = function(output, pos, options) {
var opts = extend({limit: 7}, this.options, options);
var lines = output.split('\n');
var limit = opts.limit;

@@ -37,26 +49,25 @@ // Return if we don't have enough visible lines to paginate

// position the middle of the visible list
if (this.position < middle && this.lastIndex < selected && selected - this.lastIndex < limit) {
this.position = Math.min(middle, this.position + selected - this.lastIndex);
if (this.position < middle && this.lastIndex < pos && pos - this.lastIndex < limit) {
this.position = Math.min(middle, this.position + pos - this.lastIndex);
}
// store reference to the index of the currently selected item
this.lastIndex = selected;
// store reference to the index of the currently pos item
this.lastIndex = pos;
if (opts.filterList === true) {
lines = lines.filter(Boolean);
}
// Duplicate lines to create the illusion of an infinite list
var infinite = lines.concat(lines).concat(lines).filter(Boolean);
var topIndex = Math.max(0, selected + lines.length - this.position);
var infinite = lines.concat(lines).concat(lines);
var topIndex = Math.max(0, pos + lines.length - this.position);
if (this.options.radio === true && this.firstRender) {
this.firstRender = false;
topIndex = 0;
if (!infinite[0].trim()) {
topIndex++;
}
// Create the visible list based on the limit and current cursor position
var visible = infinite.splice(topIndex, limit);
visible = visible.join('\n');
if (this.footer) {
visible += '\n';
visible += log.dim(this.footer);
}
// Create the visible list based on the limit and current cursor position
var visible = infinite.splice(topIndex, limit).join('\n');
visible += '\n';
visible += log.dim(this.footer);
// ensure that output has a leading newline, so that the first

@@ -63,0 +74,0 @@ // list item begins on the next line after the prompt question

{
"name": "terminal-paginator",
"description": "Paginator used for rendering lists or choices for prompts in the terminal.",
"version": "1.1.0",
"version": "2.0.0",
"homepage": "https://github.com/enquirer/terminal-paginator",

@@ -24,2 +24,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"debug": "^2.6.6",
"extend-shallow": "^2.0.1",
"log-utils": "^0.2.1"

@@ -26,0 +27,0 @@ },

@@ -70,2 +70,2 @@ # terminal-paginator [![NPM version](https://img.shields.io/npm/v/terminal-paginator.svg?style=flat)](https://www.npmjs.com/package/terminal-paginator) [![NPM monthly downloads](https://img.shields.io/npm/dm/terminal-paginator.svg?style=flat)](https://npmjs.org/package/terminal-paginator) [![NPM total downloads](https://img.shields.io/npm/dt/terminal-paginator.svg?style=flat)](https://npmjs.org/package/terminal-paginator)

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 07, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 24, 2017._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc