♻️ refactor(rooticolor): move color utilities to module
Create a rooticolor module for color utilities that are used in multiple locations in config
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
local bit = require("bit")
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Function to convert RGB to hexadecimal
|
||||
function M.rgb_to_hex(rgb)
|
||||
return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3])
|
||||
end
|
||||
|
||||
-- Function to get the foreground color of a highlight group
|
||||
function M.get_fg_color(hlgroup)
|
||||
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
||||
local fg = hl.fg
|
||||
if fg then
|
||||
return M.rgb_to_hex({
|
||||
bit.rshift(bit.band(fg, 0xFF0000), 16),
|
||||
bit.rshift(bit.band(fg, 0x00FF00), 8),
|
||||
bit.band(fg, 0x0000FF),
|
||||
})
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function M.get_bg_color(hlgroup)
|
||||
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
||||
local bg = hl.bg
|
||||
if bg then
|
||||
return M.rgb_to_hex({
|
||||
bit.rshift(bit.band(bg, 0xFF0000), 16),
|
||||
bit.rshift(bit.band(bg, 0x00FF00), 8),
|
||||
bit.band(bg, 0x0000FF),
|
||||
})
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user