diff --git a/dots/.nvim-environments/primary/config/lua/utils/funcs.lua b/dots/.nvim-environments/primary/config/lua/utils/funcs.lua index c7f687bd..1b873500 100755 --- a/dots/.nvim-environments/primary/config/lua/utils/funcs.lua +++ b/dots/.nvim-environments/primary/config/lua/utils/funcs.lua @@ -1,15 +1,15 @@ local U = {} U.rgbToHex = function(rgb) - return string.format('#%06x', rgb) + return string.format("#%06x", rgb) end U.hexToRgb = function(hex_str) - local hex = '[abcdef0-9][abcdef0-9]' - local pat = '^#(' .. hex .. ')(' .. hex .. ')(' .. hex .. ')$' + local hex = "[abcdef0-9][abcdef0-9]" + local pat = "^#(" .. hex .. ")(" .. hex .. ")(" .. hex .. ")$" hex_str = string.lower(hex_str) - assert(string.find(hex_str, pat) ~= nil, 'hex_to_rgb: invalid hex_str: ' .. tostring(hex_str)) + assert(string.find(hex_str, pat) ~= nil, "hex_to_rgb: invalid hex_str: " .. tostring(hex_str)) local r, g, b = string.match(hex_str, pat) return { tonumber(r, 16), tonumber(g, 16), tonumber(b, 16) } @@ -24,15 +24,20 @@ U.blend = function(fg, bg, alpha) return math.floor(math.min(math.max(0, ret), 255) + 0.5) end - return string.format('#%02X%02X%02X', blendChannel(1), blendChannel(2), blendChannel(3)) + return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3)) end U.darken = function(hex, amount, bg) - return U.blend(hex, bg or '#000000', math.abs(amount)) + return U.blend(hex, bg or "#000000", math.abs(amount)) end U.lighten = function(hex, amount, fg) - return U.blend(hex, fg or '#ffffff', math.abs(amount)) + return U.blend(hex, fg or "#ffffff", math.abs(amount)) +end + +U.get_color = function(group, attr) + local fn = vim.fn + return fn.synIDattr(fn.synIDtrans(fn.hlID(group)), attr) end return U