Permalink
Browse files

[api] Make colors strings

  • Loading branch information...
1 parent 669f5fe commit 279328d2019121d163c53ec774fb2d05c260da10 @mmalecki committed Nov 28, 2011
Showing with 25 additions and 2 deletions.
  1. +25 −2 lib/ansiparse.js
View
@@ -65,10 +65,10 @@ ansiparse = function (str) {
//
ansiState.forEach(function (ansiCode) {
if ((30 <= ansiCode) && (ansiCode <= 37)) {
- state.foreground = ansiCode;
+ state.foreground = ansiparse.foregroundColors[ansiCode];
}
else if ((40 <= ansiCode) && (ansiCode <= 47)) {
- state.background = ansiCode;
+ state.background = ansiparse.backgroundColors[ansiCode];
}
else if (ansiCode == 39) {
delete state.foreground;
@@ -95,6 +95,7 @@ ansiparse = function (str) {
state.underline = false;
}
});
+ ansiState = [];
}
else {
matchingData += str[i];
@@ -121,6 +122,28 @@ ansiparse = function (str) {
return result;
}
+ansiparse.foregroundColors = {
+ '30': 'black',
+ '31': 'red',
+ '32': 'green',
+ '33': 'yellow',
+ '34': 'blue',
+ '35': 'magenta',
+ '36': 'cyan',
+ '37': 'white'
+};
+
+ansiparse.backgroundColors = {
+ '40': 'black',
+ '41': 'red',
+ '42': 'green',
+ '43': 'yellow',
+ '44': 'blue',
+ '45': 'magenta',
+ '46': 'cyan',
+ '47': 'white'
+};
+
if (typeof module == "object" && typeof window == "undefined") {
module.exports = ansiparse;
}

0 comments on commit 279328d

Please sign in to comment.