Continuing my tradition of recoding basic mudlet functions, I have made it so that showColors takes a search argument... So many times, I don't want to read through each and every colour just to find the one I want.
So, for instance: showColors("red") would now be a valid way to use this function.
Both 'columns' and 'search' are now optional, so you can have one or the other, or both!
Other things to notice: The color names are now 'clickable', and clicking one will print the name in your command line for easy copying. Rolling over one will tell you the RGB color that it is.
function showColors(...)
local args = {...}
local n = #args
local cols, search
if n > 1 then
cols, search = args[1], args[2]
elseif n == 1 and type(args[1]) == "string" then
search = args[1]
elseif n == 1 and type(args[1]) == "number" then
cols = args[1]
elseif n == 0 then
cols = 4
search = ""
else
error("showColors: Improper usage. Use showColors(columns, search)")
end
cols = cols or 4
search = search and search:lower() or ""
local i = 1
for k,v in pairs(color_table) do
if k:lower():find(search) then
local fgc
local luminosity = (0.2126 * ((v[1]/255)^2.2)) + (0.7152 * ((v[2]/255)^2.2)) + (0.0722 * ((v[3]/255)^2.2))
if luminosity > 0.5 then
fgc = "black"
else
fgc = "white"
end
fg(fgc)
bg(k)
echoLink(k..string.rep(" ", 23-k:len()),[[printCmdLine("]]..k..[[")]],v[1] ..", "..v[2]..", "..v[3],true)
resetFormat()
echo(" ")
if i == cols then
echo"\n"
i = 1
else
i = i + 1
end
end
end
end