readline-ui
Advanced tools
Comparing version 2.0.1 to 2.1.0
53
index.js
@@ -59,8 +59,3 @@ 'use strict'; | ||
UI.prototype.onKeypress = function(str, key) { | ||
var events = utils.normalize(str, key); | ||
for (var i = 0; i < events.length; i++) { | ||
var event = events[i]; | ||
this.emit('keypress', event.key.name, event.key); | ||
this.emit(event.key.name, event.key); | ||
} | ||
utils.emitKeypress(this, str, key); | ||
}; | ||
@@ -80,12 +75,9 @@ | ||
/** | ||
* Write message to screen and setPrompt to control backspace | ||
*/ | ||
// Write message to screen and setPrompt to control backspace | ||
var promptLine = utils.lastLine(str); | ||
var rawPromptLine = this.unstyle(promptLine); | ||
// Remove the last line from our prompt. We can't rely on the str of | ||
// rl.line (mainly because of the password prompt), so just rely on it's | ||
// length. | ||
// Remove the last line from our prompt. We can't rely | ||
// on the str of rl.line (mainly because of the password | ||
// prompt), so just rely on it's length. | ||
var prompt = promptLine; | ||
@@ -107,4 +99,5 @@ if (this.rl.line.length) { | ||
// Manually insert an extra line if we're at the end of the line. This | ||
// prevents the cursor from appearing at the beginning of the current line. | ||
// Manually insert an extra line if we're at the end of | ||
// the line. This prevents the cursor from appearing at | ||
// the beginning of the current line. | ||
if (rawPromptLine.length % width === 0) { | ||
@@ -117,8 +110,5 @@ str += '\n'; | ||
/** | ||
* Re-adjust the cursor at the correct position. | ||
*/ | ||
// We need to consider parts of the prompt under the cursor as part of the bottom | ||
// string in order to correctly cleanup and re-render. | ||
// We need to consider parts of the prompt under the | ||
// cursor as part of the bottom string in order to | ||
// correctly cleanup and re-render. | ||
var promptLineUpDiff = Math.floor(rawPromptLine.length / width) - cursorPos.rows; | ||
@@ -193,5 +183,5 @@ var bottomContentHeight = promptLineUpDiff + (bottomContent ? utils.height(bottomContent) : 0); | ||
/** | ||
* Close the `readline.Interface` instance and relinquish control over the input | ||
* and output streams. Also removes event listeners, and restores/unmutes prompt | ||
* functionality. | ||
* Close the `readline.Interface` instance and relinquish | ||
* control over the input and output streams. Also removes | ||
* event listeners, and restores/unmutes prompt functionality. | ||
*/ | ||
@@ -213,4 +203,5 @@ | ||
/** | ||
* Returns an "indentity" function that calls `.close()`, which can | ||
* be used as the final `.then()` function with promises. | ||
* Returns an "indentity" function that calls `.close()`, | ||
* which can be used as the final `.then()` function with | ||
* promises. | ||
*/ | ||
@@ -227,3 +218,4 @@ | ||
/** | ||
* Default method for writing a prompt to the terminal. This can be overridden. | ||
* Default method for writing a prompt to the terminal. | ||
* This can be overridden. | ||
*/ | ||
@@ -243,5 +235,5 @@ | ||
UI.prototype.log = function() { | ||
console.log(Array(10).join('\n')); | ||
this.rl.output.unmute(); | ||
console.log.apply(console, arguments); | ||
console.log(Array(10).join('\n')); | ||
this.rl.output.mute(); | ||
}; | ||
@@ -264,3 +256,4 @@ | ||
/** | ||
* Expose `UI.create` for using a single instance across multiple prompts. | ||
* Expose `UI.create` for using a single instance across | ||
* multiple prompts. | ||
*/ | ||
@@ -267,0 +260,0 @@ |
{ | ||
"name": "readline-ui", | ||
"description": "Create readline interface to use in prompts.", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"homepage": "https://github.com/enquirer/readline-ui", | ||
@@ -25,3 +25,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"debug": "^2.6.6", | ||
"readline-utils": "^2.0.0", | ||
"readline-utils": "^2.1.0", | ||
"string-width": "^2.0.0", | ||
@@ -75,4 +75,4 @@ "strip-color": "^0.1.0" | ||
"enquirer", | ||
"prompt-choices", | ||
"prompt-question", | ||
"prompt-choices", | ||
"readline-utils" | ||
@@ -79,0 +79,0 @@ ] |
@@ -22,3 +22,3 @@ # 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#L75) | ||
### [.render](index.js#L70) | ||
@@ -33,3 +33,3 @@ Render the given `str` in the terminal, and optional `bottomContent`. | ||
### [.clearLines](index.js#L146) | ||
### [.clearLines](index.js#L136) | ||
@@ -36,0 +36,0 @@ Remove `n` lines from the bottom of the terminal |
12297
208
Updatedreadline-utils@^2.1.0