Skip to content

Commit 0234fe9

Browse files
author
Joshua Appelman
committedAug 22, 2014
Reverses application of styles, now left-to-right
The styles' application order used to to be right-to-left e.g.: ```javascript console.log(chalk.red.reset.blue('something')) // red ``` Where now it has been reversed. E.g.: ```javascript console.log(chalk.red.reset.blue('something')) // blue ``` It seems to me that this is the more intuitive application order. Closes #41
1 parent bc4f81d commit 0234fe9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
 

‎index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function applyStyle() {
5757
/*jshint validthis: true*/
5858
var nestedStyles = this._styles;
5959

60-
for (var i = 0; i < nestedStyles.length; i++) {
60+
var i = nestedStyles.length;
61+
while (i--) {
6162
var code = ansiStyles[nestedStyles[i]];
6263
// Replace any instances already present with a re-opening code
6364
// otherwise only the part of the string until said closing code

‎test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ describe('chalk', function () {
1010
});
1111

1212
it('should support applying multiple styles at once', function () {
13-
assert.equal(chalk.red.bgGreen.underline('foo'), '\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24m');
14-
assert.equal(chalk.underline.red.bgGreen('foo'), '\u001b[42m\u001b[31m\u001b[4mfoo\u001b[24m\u001b[39m\u001b[49m');
13+
assert.equal(chalk.red.bgGreen.underline('foo'), '\u001b[31m\u001b[42m\u001b[4mfoo\u001b[24m\u001b[49m\u001b[39m');
14+
assert.equal(chalk.underline.red.bgGreen('foo'), '\u001b[4m\u001b[31m\u001b[42mfoo\u001b[49m\u001b[39m\u001b[24m');
1515
});
1616

1717
it('should support nesting styles', function () {
1818
assert.equal(
1919
chalk.red('foo' + chalk.underline.bgBlue('bar') + '!'),
20-
'\u001b[31mfoo\u001b[44m\u001b[4mbar\u001b[24m\u001b[49m!\u001b[39m'
20+
'\u001b[31mfoo\u001b[4m\u001b[44mbar\u001b[49m\u001b[24m!\u001b[39m'
2121
);
2222
});
2323

@@ -29,7 +29,7 @@ describe('chalk', function () {
2929
});
3030

3131
it('should reset all styles with `.reset()`', function () {
32-
assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m');
32+
assert.equal(chalk.reset(chalk.red.bgGreen.underline('foo') + 'foo'), '\u001b[0m\u001b[31m\u001b[42m\u001b[4mfoo\u001b[24m\u001b[49m\u001b[39mfoo\u001b[0m');
3333
});
3434

3535
it('should be able to cache multiple styles', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.