Added rainbow styling

This commit is contained in:
Wes Todd 2013-08-31 19:18:58 -05:00
parent 0133342393
commit 24e6a26bbb
2 changed files with 21 additions and 0 deletions

View file

@ -60,3 +60,20 @@ chalk.supportsColor = require('has-color');
if (chalk.enabled === undefined) {
chalk.enabled = chalk.supportsColor;
}
// rainbow style
var rainbowColors = [
chalk.red,
chalk.yellow,
chalk.green,
chalk.blue,
chalk.magenta
];
chalk.rainbow = function(str) {
var arStr = str.split(''),
out = '';
for (var i in arStr) {
out += rainbowColors[i % rainbowColors.length](arStr[i]);
}
return out;
};

View file

@ -29,6 +29,10 @@ describe('chalk', function () {
it('should alias gray to grey', function () {
assert.equal(chalk.grey('foo'), '\x1b[90mfoo\x1b[39m');
});
it('should style a string in rainbow colors', function () {
assert.equal(chalk.rainbow('rygbmr g\tm\ny'), '\x1b[31mr\x1b[39m\x1b[33my\x1b[39m\x1b[32mg\x1b[39m\x1b[34mb\x1b[39m\x1b[35mm\x1b[39m\x1b[31mr\x1b[39m\x1b[33m \x1b[39m\x1b[32mg\x1b[39m\x1b[34m\t\x1b[39m\x1b[35mm\x1b[39m\x1b[31m\n\x1b[39m\x1b[33my\x1b[39m');
});
});
describe('chalk.enabled', function () {