code / nomsu

Lines6.6K Lua5.1K PEG1.3K make117
2 others 83
Markdown60 Bourne Again Shell23
(82 lines)
1 if COLOR_ENABLED then
2 local codes = {
3 normal = 0,
4 reset = 0,
5 bright = 1,
6 bold = 1,
7 dim = 2,
8 italic = 3,
9 underscore = 4,
10 ["slow blink"] = 5,
11 ["fast blink"] = 6,
12 reverse = 7,
13 inverse = 7,
14 inverted = 7,
15 hidden = 8,
16 strikethrough = 9,
17 black = 30,
18 red = 31,
19 green = 32,
20 yellow = 33,
21 blue = 34,
22 magenta = 35,
23 cyan = 36,
24 white = 37,
25 on_black = 40,
26 on_red = 41,
27 on_green = 42,
28 on_yellow = 43,
29 on_blue = 44,
30 on_magenta = 45,
31 on_cyan = 46,
32 on_white = 47
34 local inverses = {
35 [0] = 0,
36 [1] = 22,
37 [2] = 22,
38 [3] = 23,
39 [4] = 24,
40 [5] = 25,
41 [6] = 25,
42 [7] = 27,
43 [8] = 28,
44 [9] = 29,
45 [30] = 39,
46 [31] = 39,
47 [32] = 39,
48 [33] = 39,
49 [34] = 39,
50 [35] = 39,
51 [36] = 39,
52 [37] = 39,
53 [38] = 39,
54 [40] = 49,
55 [41] = 49,
56 [42] = 49,
57 [43] = 49,
58 [44] = 49,
59 [45] = 49,
60 [46] = 49,
61 [47] = 49,
62 [48] = 49
64 return function(colors, s)
65 colors = colors:gsub("on (%a+)", function(self)
66 return codes['on_' .. self]
67 end)
68 colors = colors:gsub("(%a+)", function(self)
69 return codes[self]
70 end)
71 colors = colors:gsub(" ", ";")
72 local colorize = "\x1b[" .. colors .. 'm'
73 local reset = colorize:gsub("%d+", function(c)
74 return inverses[tonumber(c)]
75 end)
76 return s and (colorize .. s .. reset) or colorize
77 end
78 else
79 return function(colors, s)
80 return (s or '')
81 end
82 end