From ba8ad6c36d48f17d3d44628e003db2635dbf5089 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Wed, 30 Sep 2015 00:31:27 +0200 Subject: [PATCH 01/18] Clear line after stopping --- spinner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spinner.js b/spinner.js index 885e536..147081c 100644 --- a/spinner.js +++ b/spinner.js @@ -35,7 +35,7 @@ var spinner = (function() { cursor.show(); } - process.stdout.write(sequence[index].replace(/./g,"\b")); + process.stdout.clearLine(); } function change_sequence(seq) { From b8cede252b66c72f5cad8d22ddd9ddbe20a754ff Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:19:41 +0100 Subject: [PATCH 02/18] + title & description --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index de63b21..11cedf8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Supper Simple Spinner for Node.js -================================= +# loading-spinner +**Loading spinner for NodeJS** This is a supper simple spinner / activity indicator for Node.js. I've used it in a few console tools that I've written in Node.js, where I've wanted to show that there is activity and that the program isn't hung. @@ -15,9 +15,8 @@ So simple it only has 3 functions. * Obviously this starts the spinner. You can give it how quickly you want it to go through the sequence of characters. Defaults to 250ms. * **Update (2015-07-24)**: start can now also take an options object with the following keys: * `hideCursor` (boolean, default: false): When true, hide the console cursor (uses TooTallNate/ansi.js) - * `doNotBlock` (boolean, default: false): When true, unref the timer so it does not prevent the process from exiting. + * `doNotBlock` (boolean, default: false): When true, unref the timer so it does not prevent the process from exiting. * `stop()` * I really shouldn't have to explain this one... * `change_sequence(sequence)` * Use this if you don't like the default spinning stick. Give it an array of strings like this `[".", "o", "0", "@", "*"]` - From 130a7128ab64595bc5cb8c4cb55dec91907e233a Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:26:45 +0100 Subject: [PATCH 03/18] renaming + complements --- package.json | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 7374d60..53092da 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,28 @@ { - "name": "simple-spinner", - "description": "A super simple spinner", - "keywords": [ - "simple", - "spinner", - "indicator" + "name": "loading-spinner", + "main": "./spinner", + "version": "1.0.0", + "description": "Loading spinner for NodeJS.", + "author": { + "name": "Ivan Gabriele", + "email": "ivan.gabriele@gmail.com", + "url": "http://www.ivangabriele.com" + }, + "contributors": [ + { + "name": "Ian McCall", + "email": "imccall@da-puck.com", + "url": "http://www.ianmccall.codes" + } ], - "version": "0.0.5", "licence": "MIT", - "author": "Ian McCall (http://www.ianmccall.codes/)", - "main": "./spinner", + "keywords": [ + "load", + "loading", + "bar", + "indicator", + "spinner" + ], "repository": { "type": "git", "url": "https://github.com/dapuck/node-simple-spinner.git" From e8d449e900f16d57a4476ed7f8a54a442cd7b019 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:30:05 +0100 Subject: [PATCH 04/18] tags --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 11cedf8..8b3963a 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # loading-spinner -**Loading spinner for NodeJS** +**Loading spinner for NodeJS.** -This is a supper simple spinner / activity indicator for Node.js. -I've used it in a few console tools that I've written in Node.js, where I've wanted to show that there is activity and that the program isn't hung. - -[![NPM](https://nodei.co/npm/simple-spinner.png?downloads=true)](https://nodei.co/npm/simple-spinner/) +[![Build Status](https://travis-ci.org/ivangabriele/loading-spinner.svg?branch=master)](https://travis-ci.org/ivangabriele/loading-spinner) +[![NPM Version](https://img.shields.io/npm/v/loading-spinner.svg?style=flat)](https://www.npmjs.org/package/loading-spinner) +[![NPM Downloads](https://img.shields.io/npm/dm/loading-spinner.svg?style=flat)](https://www.npmjs.org/package/loading-spinner) +[![Dependency Status](https://david-dm.org/ivangabriele/loading-spinner.svg)](https://david-dm.org/ivangabriele/loading-spinner) +[![devDependency Status](https://david-dm.org/ivangabriele/loading-spinner/dev-status.svg)](https://david-dm.org/ivangabriele/loading-spinner#info=devDependencies) How Simple Is It? ----------------- From 4a3156034e849354cd767ce30bad0ab63bf50458 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:32:20 +0100 Subject: [PATCH 05/18] + Travis CI --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cf19192 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: node_js +node_js: + - "5.5" + - "5.4" + - "5.3" + - "5.2" + - "5.1" + - "5.0" + - "4.2" + - "4.1" + - "4.0" From 6095af6f85828f3f1d6ecfd50a34b2170f95aeb8 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:33:23 +0100 Subject: [PATCH 06/18] full npm --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 3c3629e..d97910c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ +### Node ### + +# Logs +logs +*.log +npm-debug.log* + +# Dependency directory node_modules From 8995b344fe6a1f336a6be1c499f8e9324f884cd5 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:33:56 +0100 Subject: [PATCH 07/18] typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 53092da..1b8d7a6 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "url": "http://www.ianmccall.codes" } ], - "licence": "MIT", + "license": "MIT", "keywords": [ "load", "loading", From 1017e6d074b271e1836c33bc53007af44cdce0c8 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:34:43 +0100 Subject: [PATCH 08/18] + license --- LICENSE | 20 ++++++++++++++++++++ LICENSE.txt | 21 --------------------- 2 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 LICENSE delete mode 100644 LICENSE.txt diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0bbef25 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2015 Ivan Gabriele + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 38c6bf2..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) [year] [fullname] - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. From ffdeb3e2971b19e7c9228773e187fe1b18023cc0 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:35:46 +0100 Subject: [PATCH 09/18] lib structure --- spinner.js => lib/loading-spinner.js | 0 test.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename spinner.js => lib/loading-spinner.js (100%) diff --git a/spinner.js b/lib/loading-spinner.js similarity index 100% rename from spinner.js rename to lib/loading-spinner.js diff --git a/test.js b/test.js index dccc4d4..cef9534 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,4 @@ -var spinner = require('./spinner'); +var spinner = require('./lib/loading-spinner'); function test1() { spinner.start(); From e32d104ec46e35a15c10d7ee12978f63346744a4 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:42:57 +0100 Subject: [PATCH 10/18] first clean --- lib/loading-spinner.js | 20 +++++++++----------- test.js | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/loading-spinner.js b/lib/loading-spinner.js index 147081c..30095c1 100644 --- a/lib/loading-spinner.js +++ b/lib/loading-spinner.js @@ -1,9 +1,7 @@ -/*********** - * Spinner * - ***********/ var cursor = require('ansi')(process.stdout); -var spinner = (function() { - var sequence = ["|","/","-","\\"]; //[".", "o", "0", "@", "*"]; + +var loadingSpinner = (function() { + var sequence = ['|','/','-','\\']; //[".", "o", "0", "@", "*"]; var index = 0; var timer; var opts = {}; @@ -14,16 +12,16 @@ var spinner = (function() { if(options.hideCursor) { cursor.hide(); } - + inv = inv || 250; index = 0; process.stdout.write(sequence[index]); timer = setInterval(function() { - process.stdout.write(sequence[index].replace(/./g,"\b")); + process.stdout.write(sequence[index].replace(/./g, '\b')); index = (index < sequence.length - 1) ? index + 1 : 0; process.stdout.write(sequence[index]); },inv); - + if(options.doNotBlock) { timer.unref(); } @@ -38,7 +36,7 @@ var spinner = (function() { process.stdout.clearLine(); } - function change_sequence(seq) { + function changeSequence(seq) { if(Array.isArray(seq)) { sequence = seq; } @@ -47,8 +45,8 @@ var spinner = (function() { return { start: start, stop: stop, - change_sequence: change_sequence + changeSequence: changeSequence }; })(); -module.exports = spinner; +module.exports = loadingSpinner; diff --git a/test.js b/test.js index cef9534..14dded1 100644 --- a/test.js +++ b/test.js @@ -1,33 +1,33 @@ -var spinner = require('./lib/loading-spinner'); +var loadingSpinner = require('./lib/loading-spinner'); function test1() { - spinner.start(); + loadingSpinner.start(); setTimeout(function() { - spinner.stop(); + loadingSpinner.stop(); test2(); }, 1000); } function test2() { - spinner.change_sequence(["0o0", "o0o"]); - spinner.start(); + loadingSpinner.changeSequence(['0o0', 'o0o']); + loadingSpinner.start(); setTimeout(function() { - spinner.stop(); + loadingSpinner.stop(); test3(); }, 1000); } function test3() { - spinner.start(50,{ hideCursor : true }); + loadingSpinner.start(50,{ hideCursor : true }); setTimeout(function() { - spinner.stop(); - spinner.start(100, { doNotBlock : true }); + loadingSpinner.stop(); + loadingSpinner.start(100, { doNotBlock : true }); }, 1000); } -process.on("exit", function() { - spinner.stop(); - console.log("Have a nice day"); +process.on('exit', function() { + loadingSpinner.stop(); + console.log('Have a nice day'); }); test1(); From 8871519fbac56cc53d6602a9f3e5db47c6b76cd0 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:43:49 +0100 Subject: [PATCH 11/18] fix main --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b8d7a6..f06a110 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loading-spinner", - "main": "./spinner", + "main": "./lib/loading-spinner", "version": "1.0.0", "description": "Loading spinner for NodeJS.", "author": { From 794281923836b1b4530163ed01399931892e53b2 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 21:55:34 +0100 Subject: [PATCH 12/18] refactoring --- lib/loading-spinner.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/loading-spinner.js b/lib/loading-spinner.js index 30095c1..ab4e899 100644 --- a/lib/loading-spinner.js +++ b/lib/loading-spinner.js @@ -4,12 +4,17 @@ var loadingSpinner = (function() { var sequence = ['|','/','-','\\']; //[".", "o", "0", "@", "*"]; var index = 0; var timer; - var opts = {}; + var settings = {}; function start(inv, options) { options = options || {}; - opts = options; - if(options.hideCursor) { + + settings = { + doNotBlock: !!options.doNotBlock, + hideCursor: !!options.hideCursor + }; + + if (settings.hideCursor) { cursor.hide(); } @@ -20,25 +25,26 @@ var loadingSpinner = (function() { process.stdout.write(sequence[index].replace(/./g, '\b')); index = (index < sequence.length - 1) ? index + 1 : 0; process.stdout.write(sequence[index]); - },inv); + }, inv); - if(options.doNotBlock) { + if(settings.doNotBlock) { timer.unref(); } } function stop() { clearInterval(timer); - if(opts.hideCursor) { + + if(settings.hideCursor) { cursor.show(); } process.stdout.clearLine(); } - function changeSequence(seq) { - if(Array.isArray(seq)) { - sequence = seq; + function changeSequence(customSequence) { + if(customSequence.constructor === Array) { + sequence = customSequence; } } From 9fb9bc92e191fb033b08a0cd3e2b6e0b7b93517f Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 22:30:05 +0100 Subject: [PATCH 13/18] stdin > readline (b/c deprec), refactoring, + clearChar option --- README.md | 43 ++++++++++++++++++++++++++---------------- lib/loading-spinner.js | 36 ++++++++++++++++++++++------------- test.js | 19 +++++++++++++++++-- 3 files changed, 67 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 8b3963a..e455c76 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,30 @@ [![NPM Version](https://img.shields.io/npm/v/loading-spinner.svg?style=flat)](https://www.npmjs.org/package/loading-spinner) [![NPM Downloads](https://img.shields.io/npm/dm/loading-spinner.svg?style=flat)](https://www.npmjs.org/package/loading-spinner) [![Dependency Status](https://david-dm.org/ivangabriele/loading-spinner.svg)](https://david-dm.org/ivangabriele/loading-spinner) -[![devDependency Status](https://david-dm.org/ivangabriele/loading-spinner/dev-status.svg)](https://david-dm.org/ivangabriele/loading-spinner#info=devDependencies) - -How Simple Is It? ------------------ - -So simple it only has 3 functions. - - * `start([interval in ms], [options])` - * Obviously this starts the spinner. You can give it how quickly you want it to go through the sequence of characters. Defaults to 250ms. - * **Update (2015-07-24)**: start can now also take an options object with the following keys: - * `hideCursor` (boolean, default: false): When true, hide the console cursor (uses TooTallNate/ansi.js) - * `doNotBlock` (boolean, default: false): When true, unref the timer so it does not prevent the process from exiting. - * `stop()` - * I really shouldn't have to explain this one... - * `change_sequence(sequence)` - * Use this if you don't like the default spinning stick. Give it an array of strings like this `[".", "o", "0", "@", "*"]` + +--- + +## Installation + + npm install loading-spinner --save + +## Usage + +## Example + + var loadingSpinner = require('loading-spinner'); + + var dary = function() { + loadingSpinner.stop(); + process.stdout.write('DA-RY !'); + }; + + var legend = function() { + process.stdout.write('It\'s gonna be LE-GEN... Wait for it... '); + loadingSpinner.start(100, { + clearAfter: true + }); + setTimeout(dary, 1000); + }; + + legend(); diff --git a/lib/loading-spinner.js b/lib/loading-spinner.js index ab4e899..b78e969 100644 --- a/lib/loading-spinner.js +++ b/lib/loading-spinner.js @@ -1,15 +1,19 @@ -var cursor = require('ansi')(process.stdout); +const cursor = require('ansi')(process.stdout); +const readline = require('readline'); var loadingSpinner = (function() { - var sequence = ['|','/','-','\\']; //[".", "o", "0", "@", "*"]; - var index = 0; - var timer; - var settings = {}; + var index = 0, + sequence = ['|','/','-','\\'], + settings = {}, + spinnerTimer; - function start(inv, options) { + function start(interval, options) { + interval = interval || 100; options = options || {}; settings = { + clearChar: !!options.clearChar, + clearLine: !!options.clearLine, doNotBlock: !!options.doNotBlock, hideCursor: !!options.hideCursor }; @@ -18,28 +22,34 @@ var loadingSpinner = (function() { cursor.hide(); } - inv = inv || 250; index = 0; process.stdout.write(sequence[index]); - timer = setInterval(function() { + spinnerTimer = setInterval(function() { process.stdout.write(sequence[index].replace(/./g, '\b')); index = (index < sequence.length - 1) ? index + 1 : 0; process.stdout.write(sequence[index]); - }, inv); + }, interval); if(settings.doNotBlock) { - timer.unref(); + spinnerTimer.unref(); } } function stop() { - clearInterval(timer); + clearInterval(spinnerTimer); + + if (settings.clearChar) { + readline.moveCursor(process.stdout, -1, 0); + readline.clearLine(process.stdout, 1); + } + + if (settings.clearLine) { + readline.clearLine(process.stdout, 0); + } if(settings.hideCursor) { cursor.show(); } - - process.stdout.clearLine(); } function changeSequence(customSequence) { diff --git a/test.js b/test.js index 14dded1..e0f3da7 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,21 @@ var loadingSpinner = require('./lib/loading-spinner'); -function test1() { +var dary = function() { + loadingSpinner.stop(); + process.stdout.write('DA-RY !'); +}; + +var legend = function() { + process.stdout.write('It\'s gonna be LE-GEN... Wait for it... '); + loadingSpinner.start(100, { + clearAfter: true + }); + setTimeout(dary, 1000); +}; + +legend(); + +/*function test1() { loadingSpinner.start(); setTimeout(function() { loadingSpinner.stop(); @@ -30,4 +45,4 @@ process.on('exit', function() { console.log('Have a nice day'); }); -test1(); +test1();*/ From 6cbe69b5bffa1787e073ded2e7cfc74b97abded7 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 22:36:01 +0100 Subject: [PATCH 14/18] stdin > readline (b/c deprec), refactoring, + clearChar option --- README.md | 14 +++++++++++++- test.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e455c76..c224a12 100644 --- a/README.md +++ b/README.md @@ -14,20 +14,32 @@ ## Usage + loadingSpinner.start([Integer], + { + clearChar: [Boolean], + clearLine: [Boolean], + doNotBlock: [Boolean], + hideCursor: [Boolean] + } + ); + ## Example var loadingSpinner = require('loading-spinner'); var dary = function() { loadingSpinner.stop(); + process.stdout.write('DA-RY !'); }; var legend = function() { process.stdout.write('It\'s gonna be LE-GEN... Wait for it... '); + loadingSpinner.start(100, { - clearAfter: true + clearChar: true }); + setTimeout(dary, 1000); }; diff --git a/test.js b/test.js index e0f3da7..0311102 100644 --- a/test.js +++ b/test.js @@ -8,7 +8,7 @@ var dary = function() { var legend = function() { process.stdout.write('It\'s gonna be LE-GEN... Wait for it... '); loadingSpinner.start(100, { - clearAfter: true + hideCursor: true }); setTimeout(dary, 1000); }; From d8f81a9d6d540c952ccb09ea01c4f8111fc2f920 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 22:43:49 +0100 Subject: [PATCH 15/18] usage, refactoring --- README.md | 22 +++++++++++++++++----- lib/loading-spinner.js | 8 ++++---- test.js | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c224a12..f695a1b 100644 --- a/README.md +++ b/README.md @@ -14,15 +14,27 @@ ## Usage - loadingSpinner.start([Integer], + var loadingSpinner = require('loading-spinner'); + + // Start the loading spinner + loadingSpinner.start( + [Integer, default: 100], // Interval (in ms) between each spinner sequence element { - clearChar: [Boolean], - clearLine: [Boolean], - doNotBlock: [Boolean], - hideCursor: [Boolean] + clearChar: [Boolean, default: false], // Clear the spinner when stop() is called + clearLine: [Boolean, default: false], // Clear the entire line when stop() is called + doNotBlock: [Boolean, default: false], // Does not prevent the process from exiting + hideCursor: [Boolean, default: false] // Hide the cursor until stop() is called } ); + // Stop the loading spinner + loadingSpinner.stop(); + + // Customize the spinner sequence + loadingSpinner.setSequence( + [Array, default: ['|','/','-','\\']], // Sequence of spinner elements + ); + ## Example var loadingSpinner = require('loading-spinner'); diff --git a/lib/loading-spinner.js b/lib/loading-spinner.js index b78e969..1e079c7 100644 --- a/lib/loading-spinner.js +++ b/lib/loading-spinner.js @@ -52,16 +52,16 @@ var loadingSpinner = (function() { } } - function changeSequence(customSequence) { + function setSequence(customSequence) { if(customSequence.constructor === Array) { sequence = customSequence; } } return { - start: start, - stop: stop, - changeSequence: changeSequence + start: start, + stop: stop, + setSequence: setSequence }; })(); diff --git a/test.js b/test.js index 0311102..0e96b09 100644 --- a/test.js +++ b/test.js @@ -8,7 +8,7 @@ var dary = function() { var legend = function() { process.stdout.write('It\'s gonna be LE-GEN... Wait for it... '); loadingSpinner.start(100, { - hideCursor: true + // hideCursor: true }); setTimeout(dary, 1000); }; From b8ebe2259721d95d1325ce3f162343c3a22df757 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Tue, 26 Jan 2016 22:45:37 +0100 Subject: [PATCH 16/18] v1.1.0 --- package.json | 2 +- test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f06a110..89906fd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "loading-spinner", "main": "./lib/loading-spinner", - "version": "1.0.0", + "version": "1.1.0", "description": "Loading spinner for NodeJS.", "author": { "name": "Ivan Gabriele", diff --git a/test.js b/test.js index 0e96b09..e37a1a5 100644 --- a/test.js +++ b/test.js @@ -8,7 +8,7 @@ var dary = function() { var legend = function() { process.stdout.write('It\'s gonna be LE-GEN... Wait for it... '); loadingSpinner.start(100, { - // hideCursor: true + clearChar: true }); setTimeout(dary, 1000); }; From 96ea0612657031bbcdf22c8eac16fdfbd43a4de7 Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Sat, 30 Jan 2016 11:39:45 +0100 Subject: [PATCH 17/18] indent > 2 --- lib/loading-spinner.js | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/lib/loading-spinner.js b/lib/loading-spinner.js index 1e079c7..3e4d44a 100644 --- a/lib/loading-spinner.js +++ b/lib/loading-spinner.js @@ -2,67 +2,67 @@ const cursor = require('ansi')(process.stdout); const readline = require('readline'); var loadingSpinner = (function() { - var index = 0, - sequence = ['|','/','-','\\'], - settings = {}, - spinnerTimer; + var index = 0, + sequence = ['|', '/', '-', '\\'], + settings = {}, + spinnerTimer; - function start(interval, options) { - interval = interval || 100; - options = options || {}; + function start(interval, options) { + interval = interval || 100; + options = options || {}; - settings = { - clearChar: !!options.clearChar, - clearLine: !!options.clearLine, - doNotBlock: !!options.doNotBlock, - hideCursor: !!options.hideCursor - }; + settings = { + clearChar: !!options.clearChar, + clearLine: !!options.clearLine, + doNotBlock: !!options.doNotBlock, + hideCursor: !!options.hideCursor + }; - if (settings.hideCursor) { - cursor.hide(); - } + if (settings.hideCursor) { + cursor.hide(); + } - index = 0; - process.stdout.write(sequence[index]); - spinnerTimer = setInterval(function() { - process.stdout.write(sequence[index].replace(/./g, '\b')); - index = (index < sequence.length - 1) ? index + 1 : 0; - process.stdout.write(sequence[index]); - }, interval); + index = 0; + process.stdout.write(sequence[index]); + spinnerTimer = setInterval(function() { + process.stdout.write(sequence[index].replace(/./g, '\b')); + index = (index < sequence.length - 1) ? index + 1 : 0; + process.stdout.write(sequence[index]); + }, interval); - if(settings.doNotBlock) { - spinnerTimer.unref(); - } - } + if (settings.doNotBlock) { + spinnerTimer.unref(); + } + } - function stop() { - clearInterval(spinnerTimer); + function stop() { + clearInterval(spinnerTimer); - if (settings.clearChar) { - readline.moveCursor(process.stdout, -1, 0); - readline.clearLine(process.stdout, 1); - } + if (settings.clearChar) { + readline.moveCursor(process.stdout, -1, 0); + readline.clearLine(process.stdout, 1); + } - if (settings.clearLine) { - readline.clearLine(process.stdout, 0); - } + if (settings.clearLine) { + readline.clearLine(process.stdout, 0); + } - if(settings.hideCursor) { - cursor.show(); - } - } + if (settings.hideCursor) { + cursor.show(); + } + } - function setSequence(customSequence) { - if(customSequence.constructor === Array) { - sequence = customSequence; - } - } + function setSequence(customSequence) { + if (customSequence.constructor === Array) { + sequence = customSequence; + } + } - return { - start: start, - stop: stop, - setSequence: setSequence - }; + return { + start: start, + stop: stop, + setSequence: setSequence + }; })(); module.exports = loadingSpinner; From 692a33e72bc85b19883db2f1177701033ea93f6d Mon Sep 17 00:00:00 2001 From: Ivan Gabriele Date: Sat, 30 Jan 2016 11:43:26 +0100 Subject: [PATCH 18/18] + mocha --- package.json | 6 ++++++ test.js => test/loading-spinner.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) rename test.js => test/loading-spinner.js (94%) diff --git a/package.json b/package.json index 89906fd..f3e9837 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "main": "./lib/loading-spinner", "version": "1.1.0", "description": "Loading spinner for NodeJS.", + "scripts": { + "test": "mocha" + }, "author": { "name": "Ivan Gabriele", "email": "ivan.gabriele@gmail.com", @@ -30,5 +33,8 @@ "homepage": "https://github.com/dapuck/node-simple-spinner", "dependencies": { "ansi": "^0.3.0" + }, + "devDependencies": { + "mocha": "^2.4.5" } } diff --git a/test.js b/test/loading-spinner.js similarity index 94% rename from test.js rename to test/loading-spinner.js index e37a1a5..4b05c95 100644 --- a/test.js +++ b/test/loading-spinner.js @@ -1,4 +1,4 @@ -var loadingSpinner = require('./lib/loading-spinner'); +var loadingSpinner = require('../lib/loading-spinner'); var dary = function() { loadingSpinner.stop();