]>
Commit | Line | Data |
---|---|---|
c3efd9cc CP |
1 | function colourise(line, entity) {\r |
2 | var fg;\r | |
3 | var bg;\r | |
4 | var underline = false;\r | |
5 | var bold = false;\r | |
6 | \r | |
7 | var out = [];\r | |
8 | var xline = line.split("");\r | |
9 | var element = document.createElement("span");\r | |
10 | \r | |
11 | function isnum(x) {\r | |
12 | return x >= '0' && x <= '9';\r | |
13 | }\r | |
14 | \r | |
15 | function parsecolours(xline, i) {\r | |
16 | if(!isnum(xline[i + 1])) {\r | |
17 | fg = undefined;\r | |
18 | bg = undefined;\r | |
19 | return i;\r | |
20 | }\r | |
21 | i++;\r | |
22 | if(isnum(xline[i + 1])) {\r | |
e2757a91 | 23 | fg = parseInt(xline[i] + xline[i + 1]);\r |
c3efd9cc CP |
24 | i++;\r |
25 | } else {\r | |
e2757a91 | 26 | fg = parseInt(xline[i]);\r |
c3efd9cc CP |
27 | }\r |
28 | if(xline[i + 1] != ",")\r | |
29 | return i;\r | |
30 | if(!isnum(xline[i + 2]))\r | |
31 | return i;\r | |
32 | i+=2;\r | |
33 | \r | |
34 | if(isnum(xline[i + 1])) {\r | |
e2757a91 | 35 | bg = parseInt(xline[i] + xline[i + 1]);\r |
c3efd9cc CP |
36 | i++;\r |
37 | } else {\r | |
e2757a91 | 38 | bg = parseInt(xline[i]);\r |
c3efd9cc CP |
39 | }\r |
40 | return i;\r | |
41 | }\r | |
42 | \r | |
43 | function ac() {\r | |
44 | if(out.length > 0) {\r | |
45 | element.appendChild(document.createTextNode(out.join("")));\r | |
46 | entity.appendChild(element);\r | |
47 | out = [];\r | |
48 | }\r | |
49 | element = document.createElement("span");\r | |
50 | } \r | |
51 | function pc() {\r | |
52 | classes = []\r | |
53 | if(fg)\r | |
54 | classes.push("Xc" + fg);\r | |
55 | if(bg)\r | |
56 | classes.push("Xbc" + bg);\r | |
57 | if(bold)\r | |
58 | classes.push("Xb");\r | |
59 | if(underline)\r | |
60 | classes.push("Xu");\r | |
61 | element.className = classes.join(" ");\r | |
62 | }\r | |
63 | \r | |
64 | for(i=0;i<xline.length;i++) {\r | |
65 | var lc = xline[i];\r | |
66 | if(lc == "\x02") {\r | |
67 | ac();\r | |
68 | \r | |
69 | bold = !bold;\r | |
70 | pc();\r | |
71 | } else if(lc == "\x1F") {\r | |
72 | ac();\r | |
73 | \r | |
74 | underline = !underline;\r | |
75 | pc();\r | |
76 | } else if(lc == "\x0F") {\r | |
77 | ac();\r | |
78 | fg = undefined;\r | |
79 | bg = undefined;\r | |
80 | underline = false;\r | |
81 | bold = false;\r | |
82 | } else if(lc == "\x03") {\r | |
83 | ac();\r | |
84 | \r | |
85 | i = parsecolours(xline, i);\r | |
e2757a91 CP |
86 | if(bg > 15)\r |
87 | bg = undefined;\r | |
88 | if(fg > 15)\r | |
89 | fg = undefined;\r | |
c3efd9cc CP |
90 | pc();\r |
91 | } else {\r | |
92 | out.push(lc);\r | |
93 | }\r | |
94 | }\r | |
95 | \r | |
96 | ac();\r | |
97 | } |