Skip to content

Commit ba56f52

Browse files
authored
Merge pull request #232 from ALE-Rainbow/master
Fix #180 - Custom with multi attr failure
2 parents 21abbcb + a98deca commit ba56f52

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

lib/extendStringPrototype.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,16 @@ module['exports'] = function() {
7373
} else {
7474
if (typeof(theme[prop]) === 'string') {
7575
colors[prop] = colors[theme[prop]];
76-
addProperty(prop, function() {
77-
return colors[theme[prop]](this);
78-
});
7976
} else {
80-
addProperty(prop, function() {
81-
var ret = this;
82-
for (var t = 0; t < theme[prop].length; t++) {
83-
ret = colors[theme[prop][t]](ret);
84-
}
85-
return ret;
86-
});
77+
var tmp = colors[theme[prop][0]];
78+
for (var t = 1; t < theme[prop].length; t++) {
79+
tmp = tmp[theme[prop][t]];
80+
}
81+
colors[prop] = tmp;
8782
}
83+
addProperty(prop, function() {
84+
return colors[prop](this);
85+
});
8886
}
8987
});
9088
}

tests/basic-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,13 @@ assert.equal(typeof ('astring'.red), 'string');
6161
assert.equal(typeof ('astring'.error), 'string');
6262

6363
assert.equal(s, 'string');
64+
65+
colors.setTheme({custom: ['blue', 'bold', 'underline']});
66+
assert.equal(colors.custom(s),
67+
'\x1b[34m' + '\x1b[1m' + '\x1b[4m' + s +
68+
'\x1b[24m' + '\x1b[22m' + '\x1b[39m' );
69+
70+
colors.setTheme({custom: ['red', 'italic', 'inverse']});
71+
assert.equal(colors.custom(s),
72+
'\x1b[31m' + '\x1b[3m' + '\x1b[7m' + s +
73+
'\x1b[27m' + '\x1b[23m' + '\x1b[39m' );

tests/safe-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ colors.setTheme({error: 'red'});
5757
assert.equal(typeof (colors.red('astring')), 'string');
5858
assert.equal(typeof (colors.error('astring')), 'string');
5959

60+
colors.setTheme({custom: ['blue', 'bold', 'underline']});
61+
assert.equal(colors.custom(s),
62+
'\x1b[4m' + '\x1b[1m' + '\x1b[34m' + s +
63+
'\x1b[39m' + '\x1b[22m' + '\x1b[24m' );
64+
65+
colors.setTheme({custom: ['red', 'italic', 'inverse']});
66+
assert.equal(colors.custom(s),
67+
'\x1b[7m' + '\x1b[3m' + '\x1b[31m' + s +
68+
'\x1b[39m' + '\x1b[23m' + '\x1b[27m' );

0 commit comments

Comments
 (0)