]>
Commit | Line | Data |
---|---|---|
1 | local pairs = pairs | |
2 | local tostring = tostring | |
3 | local setmetatable = setmetatable | |
4 | local schar = string.char | |
5 | ||
6 | module 'ansicolors' | |
7 | ||
8 | local colormt = {} | |
9 | ||
10 | function colormt:__tostring() | |
11 | return self.value | |
12 | end | |
13 | ||
14 | function colormt:__concat(other) | |
15 | return tostring(self) .. tostring(other) | |
16 | end | |
17 | ||
18 | function colormt:__call(s) | |
19 | return self .. s .. _M.reset | |
20 | end | |
21 | ||
22 | colormt.__metatable = {} | |
23 | ||
24 | local function makecolor(value) | |
25 | return setmetatable({ value = schar(27) .. '[' .. tostring(value) .. 'm' }, colormt) | |
26 | end | |
27 | ||
28 | local colors = { | |
29 | -- attributes | |
30 | reset = 0, | |
31 | clear = 0, | |
32 | bright = 1, | |
33 | dim = 2, | |
34 | underscore = 4, | |
35 | blink = 5, | |
36 | reverse = 7, | |
37 | hidden = 8, | |
38 | ||
39 | -- foreground | |
40 | black = 30, | |
41 | red = 31, | |
42 | green = 32, | |
43 | yellow = 33, | |
44 | blue = 34, | |
45 | magenta = 35, | |
46 | cyan = 36, | |
47 | white = 37, | |
48 | ||
49 | -- background | |
50 | onblack = 40, | |
51 | onred = 41, | |
52 | ongreen = 42, | |
53 | onyellow = 43, | |
54 | onblue = 44, | |
55 | onmagenta = 45, | |
56 | oncyan = 46, | |
57 | onwhite = 47, | |
58 | } | |
59 | ||
60 | for c, v in pairs(colors) do | |
61 | _M[c] = makecolor(v) | |
62 | end | |
63 |