/ tests / runner / colors.lua
colors.lua
 1  -- ANSI color helpers for terminal output (byfeature-style: blue/cyan/green/red).
 2  -- Use no colors when stdout is not a TTY so CI logs stay plain.
 3  
 4  local M = {}
 5  
 6  local function use_color()
 7    if os.getenv('NO_COLOR') then return false end
 8    -- Assume color when TERM suggests a terminal; set NO_COLOR=1 in CI to disable
 9    return os.getenv('TERM') and os.getenv('TERM') ~= '' or false
10  end
11  
12  local tty = use_color()
13  
14  -- ANSI codes
15  local RESET = '\27[0m'
16  local BOLD = '\27[1m'
17  local RED = '\27[31m'
18  local GREEN = '\27[32m'
19  local CYAN = '\27[36m'
20  local BLUE = '\27[34m'
21  local WHITE = '\27[37m'
22  
23  function M.reset()
24    return tty and RESET or ''
25  end
26  
27  function M.bold_white(s)
28    return tty and (BOLD .. WHITE .. tostring(s) .. RESET) or tostring(s)
29  end
30  
31  function M.cyan(s)
32    return tty and (CYAN .. tostring(s) .. RESET) or tostring(s)
33  end
34  
35  function M.green(s)
36    return tty and (GREEN .. tostring(s) .. RESET) or tostring(s)
37  end
38  
39  function M.red(s)
40    return tty and (RED .. tostring(s) .. RESET) or tostring(s)
41  end
42  
43  function M.blue(s)
44    return tty and (BLUE .. tostring(s) .. RESET) or tostring(s)
45  end
46  
47  return M