loading-indicator
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,5 +1,13 @@ | ||
# v1.2.0 (2015/08/17) | ||
* RIP `idle.js`, long live `loading-indicator`. | ||
* Added tests. | ||
* Added CI integration. | ||
* Changed `write.js` by `log-output`. | ||
* Removed `options.moonwalk` feature. | ||
# v1.1.0 (2015/08/05) | ||
* Removed `square` preset. | ||
* Added `moonwalk` option. | ||
* Added `options.moonwalk` option. | ||
@@ -6,0 +14,0 @@ # v1.0.0 (2015/08/04) |
'use strict'; | ||
module.exports = require('./src/idle'); | ||
module.exports = require('./src/loading-indicator'); |
{ | ||
"name": "loading-indicator", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Simple and customizable command line idle status indicator.", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/rafaelrinaldi/idle.js.git" | ||
"url": "git+https://github.com/rafaelrinaldi/loading-indicator.git" | ||
}, | ||
@@ -21,2 +21,4 @@ "keywords": [ | ||
"loading", | ||
"indicator", | ||
"progress", | ||
"wait", | ||
@@ -29,9 +31,9 @@ "ui", | ||
"bugs": { | ||
"url": "https://github.com/rafaelrinaldi/idle.js/issues" | ||
"url": "https://github.com/rafaelrinaldi/loading-indicator/issues" | ||
}, | ||
"homepage": "https://github.com/rafaelrinaldi/idle.js#readme", | ||
"homepage": "https://github.com/rafaelrinaldi/loading-indicator#readme", | ||
"dependencies": { | ||
"object-assign": "^3.0.0", | ||
"write.js": "^1.0.2" | ||
"log-output": "^2.0.1", | ||
"object-assign": "^3.0.0" | ||
} | ||
} |
@@ -13,2 +13,9 @@ # loading-indicator [![Build Status](https://travis-ci.org/rafaelrinaldi/loading-indicator.svg?branch=master)](https://travis-ci.org/rafaelrinaldi/loading-indicator) | ||
```javascript | ||
var LoadingIndicator = require('loading-indicator'); | ||
var spin = new LoadingIndicator(); | ||
spin.start(); | ||
``` | ||
## API | ||
@@ -66,10 +73,2 @@ | ||
##### `options.moonwalk` ![moonwalker](http://tgnp.me/wp-content/uploads/2011/10/lunapic_132009218615037_5.gif) | ||
Type: `boolean` | ||
Default: `false` | ||
Whether or not to moonwalk when the last step of the animation is reached. | ||
This is specially useful for creating smooth animation loops. | ||
#### `loadingIndicator.start()` | ||
@@ -76,0 +75,0 @@ |
'use strict'; | ||
var objectAssign = require('object-assign'); | ||
var write = require('write.js'); | ||
var output = require('log-output'); | ||
var presets = require('./presets'); | ||
var defaults = require('./defaults'); | ||
function Idle(options) { | ||
function LoadingIndicator(options) { | ||
this.options = objectAssign(defaults, options || {}); | ||
this.sequence = this.options.sequence || presets[this.options.preset]; | ||
this.index = 0; | ||
} | ||
Idle.prototype.start = function() { | ||
this.stop(); | ||
LoadingIndicator.prototype.start = function() { | ||
this.interval = setInterval(this.render.bind(this), this.options.delay); | ||
}; | ||
Idle.prototype.stop = function() { | ||
LoadingIndicator.prototype.stop = function() { | ||
this.index = 0; | ||
this.isMoonwalking = false; | ||
output.done(); | ||
clearInterval(this.interval); | ||
}; | ||
Idle.prototype.render = function() { | ||
var output = this.options.prefix + this.sequence[this.index] + this.options.suffix; | ||
LoadingIndicator.prototype.render = function() { | ||
var frame = this.sequence[this.index++ % this.sequence.length]; | ||
var message = this.options.prefix + frame + this.options.suffix; | ||
write(output); | ||
this._updateIndex(); | ||
output(message); | ||
}; | ||
Idle.prototype._updateIndex = function() { | ||
var hasFinishedSequence = this.index === this.sequence.length - 1; | ||
var hasStartedSequence = this.index === 0; | ||
var shouldMoonwalk = this.options.moonwalk; | ||
if(shouldMoonwalk) { | ||
if(hasFinishedSequence) { | ||
this.isMoonwalking = true; | ||
} else if(hasStartedSequence) { | ||
this.isMoonwalking = false; | ||
} | ||
if(this.isMoonwalking) { | ||
this._previous(); | ||
} else { | ||
this._next(); | ||
} | ||
} else { | ||
this._next(); | ||
} | ||
}; | ||
Idle.prototype._previous = function() { | ||
if(this.index > 0) { | ||
this.index--; | ||
} | ||
}; | ||
Idle.prototype._next = function() { | ||
if(this.index < this.sequence.length - 1) { | ||
this.index++; | ||
} else { | ||
this.index = 0; | ||
} | ||
}; | ||
module.exports = Idle; | ||
module.exports = LoadingIndicator; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
'circle': '◐◓◑◒', | ||
'dots': ['', '.', '..', '...'], | ||
'dots': '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏', | ||
'bullets': [ | ||
@@ -9,0 +9,0 @@ '◎ ◎ ◎', |
13
test.js
@@ -1,4 +0,11 @@ | ||
var Idle = require('./'); | ||
var idle = new Idle({delay: 500, preset: 'dots', moonwalk: true}); | ||
'use strict'; | ||
idle.start(); | ||
var LoadingIndicator = require('./'); | ||
var spin = new LoadingIndicator(); | ||
spin.start(); | ||
setTimeout(function() { | ||
spin.stop(); | ||
process.exit(); | ||
}, 3500); |
5757
75
88
+ Addedlog-output@^2.0.1
+ Addedlog-output@2.0.2(transitive)
+ Addedlog-output-node@1.0.1(transitive)
- Removedwrite.js@^1.0.2