Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

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.

Object.defineProperty(this, 'color', {
  set: function(color) {
    // do whatever you want to do when `spinner.color` is set.
  }
});

spinner.setText('Loading rainbows');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

}, 1000);

setTimeout(() => {
spinner.done();
}, 2000);

// $ node example.js nameOfSpinner
32 changes: 30 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use \n


function Ora(options) {
if (!(this instanceof Ora)) {
Expand All @@ -18,6 +19,7 @@ function Ora(options) {
this.options = objectAssign({
text: '',
color: 'cyan',
split: false, // seperate tasks by text value
stream: process.stderr
}, options);

Expand All @@ -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 = '√';
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use log-symbols.success instead. Allthough, what if the task fails?

};

Ora.prototype.frame = function () {
var frames = this.spinner.frames;
var frame = frames[this.frameIndex];
Expand All @@ -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 () {
Expand All @@ -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;
Expand Down