[Pkg-javascript-commits] [node-cli-cursor] 01/05: New upstream version 2.1.0

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Thu Sep 28 10:55:52 UTC 2017


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-cli-cursor.

commit f865f7a59d6aa2a9819f3ee289ee5061cf2d24cb
Author: Pirate Praveen <praveen at debian.org>
Date:   Thu Sep 28 16:03:20 2017 +0530

    New upstream version 2.1.0
---
 .editorconfig  |  3 ---
 .gitattributes |  1 +
 .travis.yml    |  4 ++--
 index.js       | 31 ++++++++++++++++++++++---------
 package.json   |  9 ++++++---
 readme.md      | 15 ++++++++++-----
 test.js        | 34 ++++++++++++++--------------------
 7 files changed, 55 insertions(+), 42 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 8f9d77e..98a761d 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -10,6 +10,3 @@ insert_final_newline = true
 [{package.json,*.yml}]
 indent_style = space
 indent_size = 2
-
-[*.md]
-trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
index 176a458..391f0a4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
 * text=auto
+*.js text eol=lf
diff --git a/.travis.yml b/.travis.yml
index aea1274..b18bae5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,5 @@
 sudo: false
 language: node_js
 node_js:
-  - 'stable'
-  - '0.12'
+  - '6'
+  - '4'
diff --git a/index.js b/index.js
index d31d46b..6284a82 100644
--- a/index.js
+++ b/index.js
@@ -1,26 +1,39 @@
 'use strict';
-var restoreCursor = require('restore-cursor');
-var hidden = false;
+const restoreCursor = require('restore-cursor');
+
+let hidden = false;
+
+exports.show = stream => {
+	const s = stream || process.stderr;
+
+	if (!s.isTTY) {
+		return;
+	}
 
-exports.show = function () {
 	hidden = false;
-	process.stdout.write('\u001b[?25h');
+	s.write('\u001b[?25h');
 };
 
-exports.hide = function () {
+exports.hide = stream => {
+	const s = stream || process.stderr;
+
+	if (!s.isTTY) {
+		return;
+	}
+
 	restoreCursor();
 	hidden = true;
-	process.stdout.write('\u001b[?25l');
+	s.write('\u001b[?25l');
 };
 
-exports.toggle = function (force) {
+exports.toggle = (force, stream) => {
 	if (force !== undefined) {
 		hidden = force;
 	}
 
 	if (hidden) {
-		exports.show();
+		exports.show(stream);
 	} else {
-		exports.hide();
+		exports.hide(stream);
 	}
 };
diff --git a/package.json b/package.json
index 8297284..68e792a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "cli-cursor",
-  "version": "1.0.2",
+  "version": "2.1.0",
   "description": "Toggle the CLI cursor",
   "license": "MIT",
   "repository": "sindresorhus/cli-cursor",
@@ -10,7 +10,7 @@
     "url": "sindresorhus.com"
   },
   "engines": {
-    "node": ">=0.10.0"
+    "node": ">=4"
   },
   "scripts": {
     "test": "xo && ava"
@@ -34,10 +34,13 @@
     "command-line"
   ],
   "dependencies": {
-    "restore-cursor": "^1.0.1"
+    "restore-cursor": "^2.0.0"
   },
   "devDependencies": {
     "ava": "*",
     "xo": "*"
+  },
+  "xo": {
+    "esnext": true
   }
 }
diff --git a/readme.md b/readme.md
index 8f64582..75c18e5 100644
--- a/readme.md
+++ b/readme.md
@@ -26,15 +26,20 @@ cliCursor.toggle(unicornsAreAwesome);
 
 ## API
 
-### .show()
+### .show([stream])
 
-### .hide()
+### .hide([stream])
 
-### .toggle(force)
+### .toggle(force, [stream])
 
-`force` is useful to show or hide the cursor based an a boolean.
+`force` is useful to show or hide the cursor based on a boolean.
+
+#### stream
+
+Type: `Stream`<br>
+Default: `process.stderr`
 
 
 ## License
 
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
index 6ae456e..260e0f4 100644
--- a/test.js
+++ b/test.js
@@ -2,65 +2,59 @@ import childProcess from 'child_process';
 import test from 'ava';
 import cliCursor from './';
 
-const write = process.stdout.write;
+const write = process.stderr.write;
 const SHOW = '\u001b[?25h';
 const HIDE = '\u001b[?25l';
 
-function getStdout(fn) {
+process.stderr.isTTY = true;
+
+function getStderr(fn) {
 	let ret = '';
 
-	process.stdout.setEncoding('utf8');
-	process.stdout.write = str => {
+	process.stderr.setEncoding('utf8');
+	process.stderr.write = str => {
 		ret += str;
 	};
 
 	fn();
-	process.stdout.write = write;
+	process.stderr.write = write;
 	return ret;
 }
 
 test('show', t => {
-	t.is(getStdout(cliCursor.show), SHOW);
-	t.end();
+	t.is(getStderr(cliCursor.show), SHOW);
 });
 
 test('hide', t => {
-	t.is(getStdout(cliCursor.hide), HIDE);
-	t.end();
+	t.is(getStderr(cliCursor.hide), HIDE);
 });
 
 test('toggle', t => {
 	cliCursor.hide();
-	t.is(getStdout(cliCursor.toggle), SHOW);
-	t.end();
+	t.is(getStderr(cliCursor.toggle), SHOW);
 });
 
 test('toggle 2', t => {
 	cliCursor.show();
-	t.is(getStdout(cliCursor.toggle), HIDE);
-	t.end();
+	t.is(getStderr(cliCursor.toggle), HIDE);
 });
 
 test('toggle force', t => {
 	cliCursor.show();
-	t.is(getStdout(cliCursor.toggle.bind(null, true)), SHOW);
-	t.end();
+	t.is(getStderr(cliCursor.toggle.bind(null, true)), SHOW);
 });
 
 test('toggle force 2', t => {
 	cliCursor.hide();
-	t.is(getStdout(cliCursor.toggle.bind(null, true)), SHOW);
-	t.end();
+	t.is(getStderr(cliCursor.toggle.bind(null, true)), SHOW);
 });
 
 test('toggle force 3', t => {
 	cliCursor.show();
-	t.is(getStdout(cliCursor.toggle.bind(null, false)), HIDE);
-	t.end();
+	t.is(getStderr(cliCursor.toggle.bind(null, false)), HIDE);
 });
 
 // used to fail, see sindresorhus/log-update#2
 test('require', t => {
 	t.is(childProcess.execSync('node index.js', {encoding: 'utf8'}), '');
-	t.end();
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-cli-cursor.git



More information about the Pkg-javascript-commits mailing list