function Enum(tbl) for i = 1, #tbl do local v = tbl[i] tbl[v] = i end return tbl end -- ty stack overflow people <: -- https://stackoverflow.com/questions/6380820/get-containing-path-of-lua-file local relative_path = debug.getinfo(1).source:match("@?(.*/)") require (relative_path .. "colors") require (relative_path .. "effects") Enum = nil local function hex(str) if tonumber(str) then return tonumber(str) end if str == "a" then return 10 elseif str == "b" then return 11 elseif str == "c" then return 12 elseif str == "d" then return 13 elseif str == "e" then return 14 elseif str == "f" then return 15 end end local function todecimal(str) str = string.lower(str) local number = 0 local scale = 0 for i=string.len(str), 1, -1 do number = number + hex(string.sub(str:lower(),i,i))*16^scale scale = scale + 1 end return math.floor(number) end local function tabulateArguments(...) local text = "" for _, v in pairs({...}) do if tab then text = text .. "\t" else local tab = true end text = text .. v end return text end function string.effect(effect, ...) local tab = false local text = tabulateArguments(...) return "\027["..tostring(effect-1).."m"..text.."\027[0;m" end local function get_colormode(color) -- colors are from 0 to 1 if type(color) == "table" then return tostring(math.floor(color[1]*255+0.5)) ..";" .. tostring(math.floor(color[2]*255+0.5)) ..";" .. tostring(math.floor(color[3]*255+0.5)), "2" elseif type(color) == "string" then if string.sub(color,1,1) == "#" then color = string.sub(color,2) end local c1 = todecimal(string.sub(color,1,2)) local c2 = todecimal(string.sub(color,3,4)) local c3 = todecimal(string.sub(color,5,6)) if c1 and c2 and c3 then return c1 .. ";" .. c2 .. ";" .. c3, "2" end elseif type(color) == "number" then return color-1, "5" end end function string.color(color, ...) local tab = false local text = tabulateArguments(...) local color, color_mode = get_colormode(color) return "\027[38;" .. color_mode .. ";" .. color .. "m" .. text .. "\027[0;m" end function string.background_color(color, ...) local tab = false local text = tabulateArguments(...) local color, color_mode = get_colormode(color) return "\027[48;" .. color_mode .. ";" .. color .. "m" .. text .. "\027[0;m" end --[[ function scrollTerminalUp(amount) return "\027["..amount.."T" end]]