Replace color_strip_alpha with ensure_pango_color
color_strip_alpha was used to insert colors into Pango markup, but it did not correctly check for valid Pango colors. ensure_pango_color checks if the color is valid in Pango, and returns a placeholder if it is not.
This commit is contained in:
parent
d4c7a7ce04
commit
2ba9c8667f
|
@ -20,6 +20,8 @@ local type = type
|
||||||
local rtable = table
|
local rtable = table
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local string = string
|
local string = string
|
||||||
|
local lgi = require("lgi")
|
||||||
|
local Pango = lgi.Pango
|
||||||
local capi =
|
local capi =
|
||||||
{
|
{
|
||||||
awesome = awesome,
|
awesome = awesome,
|
||||||
|
@ -47,14 +49,13 @@ function util.deprecate(see)
|
||||||
io.stderr:write("\n" .. tb .. "\n")
|
io.stderr:write("\n" .. tb .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Strip alpha part of color.
|
--- Get a valid color for Pango markup
|
||||||
-- @param color The color.
|
-- @param color The color.
|
||||||
-- @return The color without alpha channel.
|
-- @tparam string fallback The color to return if the first is invalid. (default: black)
|
||||||
function util.color_strip_alpha(color)
|
-- @treturn string color if it is valid, else fallback.
|
||||||
if color:len() == 9 then
|
function util.ensure_pango_color(color, fallback)
|
||||||
color = color:sub(1, 7)
|
color = tostring(color)
|
||||||
end
|
return Pango.Color.parse(Pango.Color(), color) and color or fallback or "black"
|
||||||
return color
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Make i cycle.
|
--- Make i cycle.
|
||||||
|
|
Loading…
Reference in New Issue