Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lua/gitlab/actions/summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,27 @@ M.get_outer_layout_config = function()
}
end

---Return the highlight definition map. Use a light background color (the foreground color of Normal
---highlight) when vim.o.background and the `color` are dark.
---@param color string
---@return vim.api.keyset.highlight
local function label_hl(color)
local r, g, b = color:match("%#(%x%x)(%x%x)(%x%x)")
local luminance = (0.299 * tonumber(r, 16) + 0.587 * tonumber(g, 16) + 0.114 * tonumber(b, 16)) / 255
local normal = vim.api.nvim_get_hl(0, { name = "Normal", link = false })
local normal_fg = normal.fg and string.format("#%06x", normal.fg) or "#ffffff"
local bg = (vim.o.background == "dark" and luminance < 0.5) and normal_fg or nil
return { fg = color, bg = bg }
end

M.color_details = function(bufnr)
local details_namespace = vim.api.nvim_create_namespace("Details")
for i, line in ipairs(vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)) do
if line:match("^* Labels") then
for j, label in ipairs(state.LABELS) do
local start_idx, end_idx = line:find(label.Name, 1, true)
if start_idx ~= nil and end_idx ~= nil then
vim.cmd("highlight " .. "label" .. j .. " guifg=white")
vim.api.nvim_set_hl(0, ("label" .. j), { fg = label.Color })
vim.api.nvim_set_hl(0, ("label" .. j), label_hl(label.Color))
vim.hl.range(bufnr, details_namespace, ("label" .. j), { i - 1, start_idx - 1 }, { i - 1, end_idx })
end
end
Expand Down
Loading