fix one too small
[RRG-proxmark3.git] / client / lualibs / ansicolors.lua
blob290431383265c2f74487f70f903d4a469e85a6f4
1 local pairs = pairs
2 local tostring = tostring
3 local setmetatable = setmetatable
4 local schar = string.char
6 module 'ansicolors'
8 local colormt = {}
10 function colormt:__tostring()
11 return self.value
12 end
14 function colormt:__concat(other)
15 return tostring(self) .. tostring(other)
16 end
18 function colormt:__call(s)
19 return self .. s .. _M.reset
20 end
22 colormt.__metatable = {}
24 local function makecolor(value)
25 return setmetatable({ value = schar(27) .. '[' .. tostring(value) .. 'm' }, colormt)
26 end
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,
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,
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,
60 for c, v in pairs(colors) do
61 _M[c] = makecolor(v)
62 end