code / nomsu

Lines6.6K Lua5.1K PEG1.3K make117
2 others 83
Markdown60 Bourne Again Shell23
(27 lines)
1 if COLOR_ENABLED
2 codes = {
3 normal:0, reset:0, bright:1, bold:1, dim:2, italic:3
4 underscore:4, "slow blink":5, "fast blink":6, reverse:7, inverse:7
5 inverted:7, hidden:8, strikethrough: 9,
6 -- There's some other codes, but they're not currently implemented
7 black:30, red:31, green:32, yellow:33, blue:34, magenta:35
8 cyan:36, white:37, on_black:40, on_red:41, on_green:42
9 on_yellow:43, on_blue:44, on_magenta:45, on_cyan:46
10 on_white:47
12 inverses = {
13 [0]:0, [1]:22, [2]:22, [3]:23, [4]:24, [5]:25, [6]:25, [7]:27, [8]:28, [9]: 29,
14 [30]:39, [31]:39, [32]:39, [33]:39, [34]:39, [35]:39, [36]:39, [37]:39, [38]:39,
15 [40]:49, [41]:49, [42]:49, [43]:49, [44]:49, [45]:49, [46]:49, [47]:49, [48]:49,
17 return (colors, s)->
18 colors = colors\gsub "on (%a+)", => codes['on_'..@]
19 colors = colors\gsub "(%a+)", => codes[@]
20 colors = colors\gsub " ", ";"
21 colorize = "\x1b["..colors..'m'
22 reset = colorize\gsub("%d+", (c)-> inverses[tonumber(c)])
23 return s and (colorize..s..reset) or colorize
25 else
26 return (colors, s)-> (s or '')