select-shell
Advanced tools
Comparing version 1.0.1 to 1.1.2
@@ -13,3 +13,3 @@ var encode = module.exports = function (xs) { | ||
return new Buffer([ 0x1b ].concat(bytes(xs))); | ||
return new Buffer.from([ 0x1b ].concat(bytes(xs))); | ||
}; | ||
@@ -16,0 +16,0 @@ |
38
index.js
@@ -7,6 +7,5 @@ 'use strict'; | ||
*/ | ||
var events = require('events'); | ||
var eventEmitter = require('events').EventEmitter; | ||
var encode = require('./encode'); | ||
var readline = require('colors'); | ||
var colors = require('colors'); | ||
var readline = require('readline'); | ||
@@ -16,2 +15,6 @@ var stream = process.stdin; | ||
process.on('exit', function () { | ||
processOut.write(encode('[?25h')); | ||
}) | ||
/** | ||
@@ -43,3 +46,4 @@ * Expose function invoke | ||
inverse: false, | ||
prepend: false | ||
prepend: false, | ||
disableInput: true | ||
}; | ||
@@ -53,2 +57,3 @@ this.options = []; | ||
this.keypress = this.keypress.bind(this); | ||
this.onData = this.onData.bind(this); | ||
this.rl = readline.createInterface({ | ||
@@ -63,6 +68,23 @@ input: process.stdin, | ||
stream.on('error', function (err) { | ||
console.error(err); | ||
process.exit(); | ||
}) | ||
stream.on('keypress', this.keypress); | ||
stream.on('data', this.onData); | ||
}; | ||
/** | ||
* Disable input | ||
* | ||
* @api private | ||
*/ | ||
Select.prototype.onData = function () { | ||
if (this.config.disabledInput) { | ||
readline.clearLine(processOut); | ||
} | ||
} | ||
/** | ||
* Inherit from `EventEmitter.prototype`. | ||
@@ -129,5 +151,5 @@ */ | ||
Select.prototype.clearList = function (postionCursor) { | ||
readline.cursorTo(stream, 0); | ||
readline.moveCursor(stream, 0, -this.optionsLength); | ||
readline.clearScreenDown(stream); | ||
readline.cursorTo(processOut, 0); | ||
readline.moveCursor(processOut, 0, -this.optionsLength); | ||
readline.clearScreenDown(processOut); | ||
}; | ||
@@ -204,3 +226,3 @@ | ||
this.checkoption(); | ||
readline.moveCursor(stream, 0, -1);/* remove new line */ | ||
readline.moveCursor(processOut, 0, -1);/* remove new line */ | ||
this.selectoption(); | ||
@@ -296,3 +318,3 @@ } | ||
case 'return': | ||
readline.moveCursor(stream, 0, -1);/* remove new line */ | ||
readline.moveCursor(processOut, 0, -1);/* remove new line */ | ||
this.selectoption(); | ||
@@ -299,0 +321,0 @@ break; |
{ | ||
"name": "select-shell", | ||
"version": "1.0.1", | ||
"version": "1.1.2", | ||
"description": "list of select for nodejs on terminal.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -47,3 +47,4 @@ select-shell | ||
inverse: true, | ||
prepend: true | ||
prepend: true, | ||
disableInput: true | ||
} | ||
@@ -84,3 +85,4 @@ ); | ||
inverse: false, | ||
prepend: false | ||
prepend: false, | ||
disableInput: true | ||
} | ||
@@ -87,0 +89,0 @@ ); |
26699
325
112