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>
This commit is contained in:
parent
44f64eee58
commit
9a24779425
|
@ -0,0 +1,30 @@
|
|||
---------------------------------------------------------------------------
|
||||
-- @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
|
|
@ -0,0 +1,11 @@
|
|||
---------------------------------------------------------------------------
|
||||
-- @author Uli Schlachter
|
||||
-- @copyright 2010 Uli Schlachter
|
||||
-- @release @AWESOME_VERSION@
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
require("gears.color")
|
||||
|
||||
module("gears")
|
||||
|
||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
Loading…
Reference in New Issue