Skip to content

Commit

Permalink
lualine dynamicism 💡
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry committed Jun 15, 2024
1 parent 3ba698c commit 1c75eb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
16 changes: 12 additions & 4 deletions nvim/lua/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ local M = {}
---@return table properties # the highlight group properties
function M.get_hlgroup(name, fallback)
if vim.fn.hlexists(name) == 1 then
local hl
hl = vim.api.nvim_get_hl(0, { name = name, link = false })
if not hl.fg then hl.fg = "NONE" end
if not hl.bg then hl.bg = "NONE" end
local group = vim.api.nvim_get_hl(0, { name = name })

local hl = {
fg = group.fg == nil and "NONE" or M.parse_hex(group.fg),
bg = group.bg == nil and "NONE" or M.parse_hex(group.bg),
}

return hl
end
return fallback or {}
end

--- Parse a given integer color to a hex value.
function M.parse_hex(int_color)
return string.format("#%x", int_color)
end

return M
20 changes: 10 additions & 10 deletions nvim/lua/plugins/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ return {
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
opts = function()
local colors = require("cyberdream.colors").default
local cyberdream = require("lualine.themes.cyberdream").get_theme()
local utils = require("core.utils")
local copilot_colors = {
[""] = { fg = colors.grey, bg = colors.none },
["Normal"] = { fg = colors.grey, bg = colors.none },
["Warning"] = { fg = colors.red, bg = colors.none },
["InProgress"] = { fg = colors.yellow, bg = colors.none },
[""] = utils.get_hlgroup("Comment"),
["Normal"] = utils.get_hlgroup("Comment"),
["Warning"] = utils.get_hlgroup("DiagnosticError"),
["InProgress"] = utils.get_hlgroup("DiagnosticWarn"),
}

return {
options = {
component_separators = { left = " ", right = " " },
section_separators = { left = " ", right = " " },
theme = cyberdream,
theme = "auto",
globalstatus = true,
disabled_filetypes = { statusline = { "dashboard", "alpha" } },
},
Expand Down Expand Up @@ -43,14 +43,14 @@ return {
cond = function()
return package.loaded["nvim-navic"] and require("nvim-navic").is_available()
end,
color = { fg = colors.grey, bg = colors.none },
color = utils.get_hlgroup("Comment", nil),
},
},
lualine_x = {
{
require("lazy.status").updates,
cond = require("lazy.status").has_updates,
color = { fg = colors.green },
color = utils.get_hlgroup("DiffAdd"),
},
{
function()
Expand Down Expand Up @@ -78,7 +78,7 @@ return {
},
{
"location",
color = { fg = colors.cyan, bg = colors.none },
color = utils.get_hlgroup("DiffChange"),
},
},
lualine_z = {
Expand Down

0 comments on commit 1c75eb8

Please sign in to comment.