From 1dfa32dcd0638575b0235d6f2ed6930d8db2430d Mon Sep 17 00:00:00 2001 From: ghaiklor Date: Tue, 17 Nov 2015 13:06:57 +0200 Subject: [PATCH] feat(cursor): Implements possibility to add multiply pipes before\after cursor stream --- src/Cursor.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Cursor.js b/src/Cursor.js index afd6ef7..78453ed 100644 --- a/src/Cursor.js +++ b/src/Cursor.js @@ -30,17 +30,16 @@ export class Cursor { /** * Creates new Cursor instance * @constructor - * @param {Stream|Boolean} [stdout = process.stdout] - * @param {Stream|Boolean} [stdin = false] + * @param {Array} [stdout] + * @param {Array} [stdin] */ - constructor({stdout = process.stdout, stdin = false}) { - // TODO: implement chain of transform streams for cursor + constructor({stdout = [process.stdout], stdin = []}) { this._cursor = charm(); - if (stdout) this._cursor.pipe(stdout); - if (stdin) stdin.pipe(this._cursor); + if (stdout.length > 0) stdout.reduce((cursor, pipe) => cursor.pipe(pipe), this._cursor); + if (stdin.length > 0) stdin.reduce((cursor, pipe) => cursor.pipe(pipe)).pipe(this._cursor); - this.off('^C').on('^C', this._onExit); + process.on('exit', this._onExit.bind(this)); } /** @@ -239,13 +238,12 @@ export class Cursor { } /** - * Triggers when user types ^C combination for exit + * Triggers when program is closing * @private * @returns {Cursor} */ _onExit() { this.reset(); - process.exit(0); } /**