Skip to content

Commit

Permalink
feat(cursor): Implements possibility to add multiply pipes before\aft…
Browse files Browse the repository at this point in the history
…er cursor stream
  • Loading branch information
ghaiklor committed Nov 17, 2015
1 parent 36f65ba commit 1dfa32d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/Cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 1dfa32d

Please sign in to comment.