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 0.1.0 to 0.2.0

19

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

@@ -13,2 +13,3 @@

function Paginator(options) {
debug('initializing from <%s>', __filename);
this.options = options || {};

@@ -20,7 +21,11 @@ this.lastIndex = 0;

Paginator.prototype.paginate = function(output, selected, pageSize) {
var m = output.match(/^\n+/);
var prefix = m ? m[0] : '';
output = output.replace(/^\n+/, '');
pageSize = pageSize || this.options.pageSize || 7;
var lines = output.split('\n');
// Make sure there's enough lines to paginate
if (lines.length <= pageSize + 2) {
// return if there are not enough lines to paginate
if (pageSize >= lines.length - 2) {
return output;

@@ -30,3 +35,3 @@ }

// Move the pointer when a down keypress is entered, and limit it to 3
if (this.pointer < 3 && this.lastIndex < selected && selected - this.lastIndex < 9) {
if (this.pointer < 3 && this.lastIndex < selected && (selected - this.lastIndex) < 9) {
this.pointer = Math.min(3, this.pointer + selected - this.lastIndex);

@@ -38,7 +43,9 @@ }

// Duplicate the lines so it give an infinite list look
var infinite = flatten([lines, lines, lines]);
var infinite = lines.concat(lines).concat(lines);
var topIndex = Math.max(0, selected + lines.length - this.pointer);
var section = infinite.splice(topIndex, pageSize).join('\n');
return section + '\n' + log.dim('(Move up and down to reveal more choices)');
section += '\n';
section += log.dim('(Move up and down to reveal more choices)');
return prefix + section;
};

@@ -45,0 +52,0 @@

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

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

"dependencies": {
"arr-flatten": "^1.0.1",
"debug": "^2.2.0",
"log-utils": "^0.2.1"

@@ -84,2 +84,2 @@ },

}
}
}
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