Created
July 29, 2015 03:40
-
-
Save aikar/8fd4b836e46ebc28db4f to your computer and use it in GitHub Desktop.
node.js / javascript Methods to convert section symbol minecraft color codes into Bash Color sequences, for use in shell output. Credits to mcrcon for the color code map.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var colors = { | |
0: "\033[0;30m", /* 00 BLACK 0x30 */ | |
1: "\033[0;34m", /* 01 BLUE 0x31 */ | |
2: "\033[0;32m", /* 02 GREEN 0x32 */ | |
3: "\033[0;36m", /* 03 CYAN 0x33 */ | |
4: "\033[0;31m", /* 04 RED 0x34 */ | |
5: "\033[0;35m", /* 05 PURPLE 0x35 */ | |
6: "\033[0;33m", /* 06 GOLD 0x36 */ | |
7: "\033[0;37m", /* 07 GREY 0x37 */ | |
8: "\033[1;30m", /* 08 DGREY 0x38 */ | |
9: "\033[1;34m", /* 09 LBLUE 0x39 */ | |
a: "\033[1;32m", /* 10 LGREEN 0x61 */ | |
b: "\033[1;36m", /* 11 LCYAN 0x62 */ | |
c: "\033[1;31m", /* 12 LRED 0x63 */ | |
d: "\033[1;35m", /* 13 LPURPLE 0x64 */ | |
e: "\033[1;33m", /* 14 YELLOW 0x65 */ | |
f: "\033[1;37m", /* 15 WHITE 0x66 */ | |
}; | |
function c(r, msg) { | |
return '§' + r + msg + '§r'; | |
} | |
function mccolor(str) { | |
return str.replace(/§([0-9a-fr])/g, function(m, contents) { | |
return colors[contents] || "\033[0m"; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment