local pprint = require 'libs.pprint' local utils = {} utils.term = { reset = "\x1b[m", bold = "\x1b[1m", italic = "\x1b[3m", fg = { rgb = function(r, g, b) return "\x1b[38;2;" .. tostring(r) .. ";" .. tostring(g) .. ";" .. tostring(b) .. "m" end, default = "\x1b[39m", black = "\x1b[38;5;16m", red = "\x1b[31m", green = "\x1b[32m", yellow = "\x1b[33m", blue = "\x1b[38;5;27m", magenta = "\x1b[35m", cyan = "\x1b[36m", white = "\x1b[37m", dark_grey = "\x1b[90m", light_red = "\x1b[91m", light_green = "\x1b[92m", light_yellow = "\x1b[93m", light_blue = "\x1b[94m", light_magenta = "\x1b[95m", light_cyan = "\x1b[96m", orange = "\x1b[38;5;202m", light_orange = "\x1b[38;5;208m", purple = "\x1b[38;5;93m", light_purple = "\x1b[38;5;99m", }, bg = { default = "\x1b[49m", black = "\x1b[40m", red = "\x1b[41m", green = "\x1b[42m", yellow = "\x1b[43m", blue = "\x1b[44m", magenta = "\x1b[45m", cyan = "\x1b[46m", white = "\x1b[47m", dark_grey = "\x1b[100m", light_red = "\x1b[101m", light_green = "\x1b[102m", light_yellow = "\x1b[103m", light_blue = "\x1b[104m", light_magenta = "\x1b[105m", light_cyan = "\x1b[106m", orange = "\x1b[48;5;202m", light_orange = "\x1b[48;5;208m", purple = "\x1b[48;5;93m", light_purple = "\x1b[48;5;99m", light_gray = "\x1b[48;5;234m", }, } local function log_impl(prefix, prefix_col) return function(...) local args = {...} local len = select('#', ...) io.write( utils.term.fg[prefix_col] .. prefix .. utils.term.reset ) for ix = 1,len do pprint.pformat(args[ix], nil, io.write) io.write(' ') end io.write('\n') end end utils.log = { print = pprint.pprint, info = log_impl('[INFO]: ', 'green'), debug = log_impl('[DEBUG]: ', 'blue'), warn = log_impl('[WARN]: ', 'yellow'), err = log_impl('[ERR]: ', 'red'), fatal = log_impl('[FATAL]: ', 'red'), } return utils