-
-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #2: Multi-line output (log/list) #4
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,19 @@ var Ora = require('./'); | |
|
||
var spinner = new Ora({ | ||
text: 'Loading unicorns', | ||
spinner: process.argv[2] | ||
spinner: process.argv[2], | ||
split: true | ||
}); | ||
|
||
spinner.start(); | ||
|
||
setTimeout(() => { | ||
spinner.color = 'yellow'; | ||
spinner.text = 'Loading rainbows'; | ||
spinner.setColor('yellow'); | ||
spinner.setText('Loading rainbows'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
}, 1000); | ||
|
||
setTimeout(() => { | ||
spinner.done(); | ||
}, 2000); | ||
|
||
// $ node example.js nameOfSpinner |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ var chalk = require('chalk'); | |
var cliCursor = require('cli-cursor'); | ||
var cliSpinners = require('cli-spinners'); | ||
var objectAssign = require('object-assign'); | ||
var EOL = require('os').EOL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
|
||
function Ora(options) { | ||
if (!(this instanceof Ora)) { | ||
|
@@ -18,6 +19,7 @@ function Ora(options) { | |
this.options = objectAssign({ | ||
text: '', | ||
color: 'cyan', | ||
split: false, // seperate tasks by text value | ||
stream: process.stderr | ||
}, options); | ||
|
||
|
@@ -35,8 +37,28 @@ function Ora(options) { | |
this.id = null; | ||
this.frameIndex = 0; | ||
this.enabled = (this.stream && this.stream.isTTY) && !process.env.CI; | ||
this.completed = '√'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
} | ||
|
||
Ora.prototype.setColor = function (color) { | ||
this.color = color; | ||
}; | ||
|
||
Ora.prototype.setText = function (text) { | ||
if (this.options.split) { | ||
if (this.text !== text) { | ||
this.complete(); | ||
} | ||
} | ||
this.text = text; | ||
}; | ||
|
||
Ora.prototype.complete = function () { | ||
this.clear(); | ||
var tick = chalk.green(this.completed); | ||
this.render(tick + ' ' + this.text + EOL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use log-symbols |
||
}; | ||
|
||
Ora.prototype.frame = function () { | ||
var frames = this.spinner.frames; | ||
var frame = frames[this.frameIndex]; | ||
|
@@ -59,9 +81,10 @@ Ora.prototype.clear = function () { | |
this.stream.cursorTo(0); | ||
}; | ||
|
||
Ora.prototype.render = function () { | ||
Ora.prototype.render = function (buffer) { | ||
buffer = buffer ? buffer : this.frame(); | ||
this.clear(); | ||
this.stream.write(this.frame()); | ||
this.stream.write(buffer); | ||
}; | ||
|
||
Ora.prototype.start = function () { | ||
|
@@ -74,6 +97,11 @@ Ora.prototype.start = function () { | |
this.id = setInterval(this.render.bind(this), this.interval); | ||
}; | ||
|
||
Ora.prototype.done = function () { | ||
this.complete(); | ||
this.stop(); | ||
}; | ||
|
||
Ora.prototype.stop = function () { | ||
if (!this.enabled) { | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
Object.defineProperty
to do the same thing.