Sun calculation js library which is fully based on formula from http://aa.quae.nl/en/reken/zonpositie.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.1 KiB

7 years ago
'use strict';
/**
* @module Progress
*/
7 years ago
/**
* Module dependencies.
*/
7 years ago
var Base = require('./base');
var inherits = require('../utils').inherits;
var color = Base.color;
var cursor = Base.cursor;
7 years ago
/**
* Expose `Progress`.
*/
exports = module.exports = Progress;
/**
* General progress bar color.
*/
Base.colors.progress = 90;
/**
* Initialize a new `Progress` bar test reporter.
*
7 years ago
* @public
* @class
* @memberof Mocha.reporters
* @extends Mocha.reporters.Base
* @api public
7 years ago
* @param {Runner} runner
* @param {Object} options
*/
7 years ago
function Progress (runner, options) {
7 years ago
Base.call(this, runner);
7 years ago
var self = this;
var width = Base.window.width * 0.50 | 0;
var total = runner.total;
var complete = 0;
var lastN = -1;
7 years ago
// default chars
7 years ago
options = options || {};
var reporterOptions = options.reporterOptions || {};
options.open = reporterOptions.open || '[';
options.complete = reporterOptions.complete || '▬';
options.incomplete = reporterOptions.incomplete || Base.symbols.dot;
options.close = reporterOptions.close || ']';
options.verbose = reporterOptions.verbose || false;
7 years ago
// tests started
7 years ago
runner.on('start', function () {
7 years ago
console.log();
cursor.hide();
});
// tests complete
7 years ago
runner.on('test end', function () {
7 years ago
complete++;
7 years ago
var percent = complete / total;
var n = width * percent | 0;
var i = width - n;
if (n === lastN && !options.verbose) {
7 years ago
// Don't re-render the line if it hasn't changed
return;
}
lastN = n;
cursor.CR();
process.stdout.write('\u001b[J');
process.stdout.write(color('progress', ' ' + options.open));
process.stdout.write(Array(n).join(options.complete));
process.stdout.write(Array(i).join(options.incomplete));
process.stdout.write(color('progress', options.close));
if (options.verbose) {
process.stdout.write(color('progress', ' ' + complete + ' of ' + total));
}
});
// tests are complete, output some stats
// and the failures if any
7 years ago
runner.once('end', function () {
7 years ago
cursor.show();
console.log();
self.epilogue();
});
}
/**
* Inherit from `Base.prototype`.
*/
7 years ago
inherits(Progress, Base);