awesome/lib/gears/color.lua.in
Uli Schlachter 9a24779425 Implement color parsing
This adds a lua module for parsing colors. Named colors like "black" aren't
supported, but #rrggbb and #rrggbbaa colors do work.

Signed-off-by: Uli Schlachter <psychon@znc.in>
2010-09-09 16:54:57 +02:00

30 lines
836 B
Lua

---------------------------------------------------------------------------
-- @author Uli Schlachter
-- @copyright 2010 Uli Schlachter
-- @release @AWESOME_VERSION@
---------------------------------------------------------------------------
local setmetatable = setmetatable
local string = string
local table = table
local tonumber = tonumber
local unpack = unpack
module("gears.color")
-- Thanks to #lua for this. :)
function parse_color(col)
local rgb = {}
for pair in string.gmatch(col, "[^#].") do
table.insert(rgb, tonumber(pair, 16) / 255)
end
while #rgb < 4 do
table.insert(rgb, 1)
end
return unpack(rgb)
end
setmetatable(_M, { __call = function (_, ...) return parse_color(...) end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80