showColors()

Share your scripts and packages with other Mudlet users.
Post Reply
Phoenix
Posts: 92
Joined: Tue Feb 15, 2011 3:23 am

showColors()

Post by Phoenix »

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.
Code: [show] | [select all] lua
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
Last edited by Phoenix on Tue Jan 08, 2013 4:46 am, edited 7 times in total.

Kurios
Posts: 5
Joined: Sat Feb 26, 2011 11:04 pm

Re: showColors()

Post by Kurios »

you are such a code snob :P

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: showColors()

Post by Vadi »

Useful improvement

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: showColors()

Post by Vadi »

Hi, the current iteration doesn't allow you to just do showColors(), could you fix that?

Phoenix
Posts: 92
Joined: Tue Feb 15, 2011 3:23 am

Re: showColors()

Post by Phoenix »

Wow, major oversight on my part. Fixed that now. I've also defaulted the columns to 4 instead of 3, as 3 is just... well, 4 is what I've always seen used and used myself. Feel free to flop that back to 3 if there is a reason for it.

Post Reply