Permalink
Browse files

[refactor] Put styles into a hash

  • Loading branch information...
1 parent 28ae4ec commit ed4e28da94a5a80d64df12beee644231ee580211 @mmalecki committed Dec 4, 2011
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/ansiparse.js
View
16 lib/ansiparse.js
@@ -76,14 +76,8 @@ ansiparse = function (str) {
else if (ansiCode == 49) {
delete state.background;
}
- else if (ansiCode == 1) {
- state.bold = true;
- }
- else if (ansiCode == 3) {
- state.italic = true;
- }
- else if (ansiCode == 4) {
- state.underline = true;
+ else if (ansiparse.styles[ansiCode]) {
+ state[ansiparse.styles[ansiCode]] = true;
}
else if (ansiCode == 22) {
state.bold = false;
@@ -149,6 +143,12 @@ ansiparse.backgroundColors = {
'47': 'white'
};
+ansiparse.styles = {
+ '1': 'bold',
+ '3': 'italic',
+ '4': 'underline'
+};
+
if (typeof module == "object" && typeof window == "undefined") {
module.exports = ansiparse;
}

0 comments on commit ed4e28d

Please sign in to comment.