Skip to content

Instantly share code, notes, and snippets.

@passcod
Created October 31, 2012 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passcod/3984651 to your computer and use it in GitHub Desktop.
Save passcod/3984651 to your computer and use it in GitHub Desktop.
woot color2
/* Source: */
String.prototype.color2 = function(fg,bg) {
var conv = function(thing, _default) {
if (+thing < 16 && +thing > -1) { return +thing; }
thing = "white black blue green red brown purple orange yellow lime teal cyan royal pink grey silver".split(" ").indexOf(thing);
if (thing != -1) { return thing; }
return _default;
};
fg = conv(fg, 2);
bg = conv(bg, "");
bg = bg && ","+bg;
return "\x03" + fg + bg + this + "\x0F";
};
/* Minified: */
String.prototype.color2=function(d,b){function c(a,b){if(16>+a&&-1<+a)return+a;a="white black blue green red brown purple orange yellow lime teal cyan royal pink grey silver".split(" ").indexOf(a);return-1!=a?a:b}b=c(b,"");return"\x03"+c(d,2)+(b&&","+b)+this+"\x0f"};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment