Socket
Socket
Sign inDemoInstall

readline-ui

Package Overview
Dependencies
25
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 2.2.0

70

index.js

@@ -6,3 +6,2 @@ 'use strict';

var stringWidth = require('string-width');
var stripColor = require('strip-color');
var utils = require('readline-utils');

@@ -46,13 +45,18 @@ var cached;

}
this.force = this.forceClose.bind(this);
this.onKeypress = this.onKeypress.bind(this);
this.input.on('keypress', this.onKeypress);
this.forceClose = this.forceClose.bind(this);
this.input.on('keypress', this.onKeypress.bind(this));
this.rl.resume();
this.rl.on('line', this.emit.bind(this, 'line'));
this.rl.on('SIGINT', this.force);
process.on('exit', this.force);
this.rl.on('SIGINT', this.forceClose);
process.on('exit', this.forceClose);
};
/**
* Emit keypress events
* Handle `keypress` events.
*
* @param {String} `str`
* @param {Object} `key`
* @return {undefined}
* @api public
*/

@@ -65,5 +69,5 @@

/**
* Render the given `str` in the terminal, and optional `bottomContent`.
* Render the given `str` in the terminal, and optional `footer`.
* @param {String} `str`
* @param {String} `bottomContent`
* @param {String} `footer`
* @return {undefined}

@@ -73,3 +77,3 @@ * @api public

UI.prototype.render = function(str, bottomContent) {
UI.prototype.render = function(str, footer) {
this.rl.output.unmute();

@@ -80,3 +84,3 @@ this.clearLines(this.appendedLines);

var promptLine = utils.lastLine(str);
var rawPromptLine = this.unstyle(promptLine);
var rawPromptLine = utils.unstyle(promptLine);

@@ -94,8 +98,8 @@ // Remove the last line from our prompt. We can't rely

// setPrompt will change cursor position, now we can get correct value
var cursorPos = this.rl._getCursorPos();
var cursorPos = this.cacheCursorPos();
var width = utils.cliWidth(this.rl);
str = utils.forceLineReturn(str, width);
if (bottomContent) {
bottomContent = utils.forceLineReturn(bottomContent, width);
if (footer) {
footer = utils.forceLineReturn(footer, width);
}

@@ -110,3 +114,3 @@

var fullContent = str + (bottomContent ? '\n' + bottomContent : '');
var fullContent = str + (footer ? '\n' + String(footer) : '');
this.rl.output.write(fullContent);

@@ -118,5 +122,5 @@

var promptLineUpDiff = Math.floor(rawPromptLine.length / width) - cursorPos.rows;
var bottomContentHeight = promptLineUpDiff + (bottomContent ? utils.height(bottomContent) : 0);
if (bottomContentHeight > 0) {
utils.up(this.rl, bottomContentHeight);
var footerHeight = promptLineUpDiff + (footer ? utils.height(footer) : 0);
if (footerHeight > 0) {
utils.up(this.rl, footerHeight);
}

@@ -129,7 +133,7 @@

// Adjust cursor on the right
var newPos = this.unstyle(lastLine).length;
var newPos = utils.unstyle(lastLine).length;
utils.right(this.rl, newPos);
// Set up state for next re-rendering
this.appendedLines = bottomContentHeight;
this.appendedLines = footerHeight;
this.height = utils.height(fullContent);

@@ -157,3 +161,3 @@ this.rl.output.mute();

this.cursorPos = utils.cursorPosition(this.rl);
return this;
return this.cursorPos;
};

@@ -172,10 +176,2 @@

/**
* Proxy to `.write` on the readline instance
*/
UI.prototype.write = function() {
this.rl.write.apply(this.rl, arguments);
};
/**
* Pause the input stream, allowing it to be resumed later if necessary.

@@ -227,6 +223,6 @@ */

UI.prototype.end = function(linefeed) {
UI.prototype.end = function(newline) {
this.rl.setPrompt('');
this.rl.output.unmute();
this.rl.output.write(linefeed !== false ? '\n' : '');
this.rl.output.write(newline !== false ? '\n' : '');
utils.cursorShow(this.rl);

@@ -236,3 +232,3 @@ };

/**
* Convenience method for debugging
* Utility for writing to stdout.
*/

@@ -242,3 +238,5 @@

this.rl.output.unmute();
console.log();
console.log.apply(console, arguments);
console.log();
this.rl.output.mute();

@@ -248,10 +246,2 @@ };

/**
* Convenience method for debugging
*/
UI.prototype.unstyle = function(str) {
return stripColor(str);
};
/**
* Expose `UI`

@@ -258,0 +248,0 @@ */

{
"name": "readline-ui",
"description": "Create readline interface to use in prompts.",
"version": "2.1.0",
"version": "2.2.0",
"homepage": "https://github.com/enquirer/readline-ui",

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

"readline-utils": "^2.1.0",
"string-width": "^2.0.0",
"strip-color": "^0.1.0"
"string-width": "^2.0.0"
},

@@ -30,0 +29,0 @@ "devDependencies": {

@@ -22,5 +22,5 @@ # readline-ui [![NPM version](https://img.shields.io/npm/v/readline-ui.svg?style=flat)](https://www.npmjs.com/package/readline-ui) [![NPM monthly downloads](https://img.shields.io/npm/dm/readline-ui.svg?style=flat)](https://npmjs.org/package/readline-ui) [![NPM total downloads](https://img.shields.io/npm/dt/readline-ui.svg?style=flat)](https://npmjs.org/package/readline-ui) [![Linux Build Status](https://img.shields.io/travis/enquirer/readline-ui.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/readline-ui)

### [.render](index.js#L70)
### [.onKeypress](index.js#L62)
Render the given `str` in the terminal, and optional `bottomContent`.
Handle `keypress` events.

@@ -30,7 +30,17 @@ **Params**

* `str` **{String}**
* `bottomContent` **{String}**
* `key` **{Object}**
* `returns` **{undefined}**
### [.clearLines](index.js#L136)
### [.render](index.js#L74)
Render the given `str` in the terminal, and optional `footer`.
**Params**
* `str` **{String}**
* `footer` **{String}**
* `returns` **{undefined}**
### [.clearLines](index.js#L140)
Remove `n` lines from the bottom of the terminal

@@ -93,2 +103,2 @@

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

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc