feat(lualine): add apply_todo_highlights function for enhanced icon highlighting

This commit is contained in:
2024-08-29 14:47:57 -04:00
parent c9ff704dee
commit 8ae7e9edb4
2 changed files with 90 additions and 36 deletions
+65 -36
View File
@@ -5,30 +5,6 @@
local utils = require("utils") local utils = require("utils")
local rootils = utils.rootiest local rootils = utils.rootiest
local function apply_todo_highlights(status_string)
-- Define patterns and associated highlight groups
local patterns = {
{ icon = "", hl = "lualine_c_diagnostics_info_normal" },
{ icon = "", hl = "lualine_c_diagnostics_warning_normal" },
{ icon = "", hl = "lualine_c_diagnostics_warning_normal" },
{ icon = "", hl = "lualine_c_diagnostics_hint_normal" },
{ icon = "", hl = "lualine_c_diagnostics_hint_normal" },
}
-- Apply the highlights
for _, pattern in ipairs(patterns) do
status_string = status_string:gsub(
vim.pesc(pattern.icon),
"%#" .. pattern.hl .. "#" .. pattern.icon
)
end
-- Reset highlight to normal after the string
status_string = status_string .. "%#LualineNormal#"
return status_string
end
return { return {
"nvim-lualine/lualine.nvim", "nvim-lualine/lualine.nvim",
dependencies = { dependencies = {
@@ -48,15 +24,15 @@ return {
opts = function() opts = function()
local icons = LazyVim.config.icons local icons = LazyVim.config.icons
-- Restore laststatus
vim.o.laststatus = vim.g.lualine_laststatus vim.o.laststatus = vim.g.lualine_laststatus
-- Define todo-comments component
local todos_component = local todos_component =
require("todos-lualine").component(require("data").types.todo.lualine()) require("todos-lualine").component(require("data").types.todo.lualine())
-- todos_component = apply_todo_highlights(todos_component)
local opts = { local opts = {
options = { options = { -- General options
theme = "auto", theme = "auto",
globalstatus = vim.o.laststatus == 3, globalstatus = vim.o.laststatus == 3,
disabled_filetypes = { disabled_filetypes = {
@@ -65,15 +41,29 @@ return {
section_separators = { left = "", right = "" }, section_separators = { left = "", right = "" },
component_separators = { left = "", right = "" }, component_separators = { left = "", right = "" },
}, },
sections = { sections = { -- Sections
lualine_a = { lualine_a = {
{ -- Mode { -- Mode
"mode", "mode",
icon = require("data").types.logo.icon,
padding = { left = 1, right = 0 },
}, },
}, },
lualine_b = { lualine_b = {
{ -- Branch { -- Branch
"branch", "branch",
separator = "",
padding = { left = 1, right = 0 },
},
{ -- Todo
todos_component,
cond = function()
return rootils.is_window_wide_enough(100)
end,
padding = { left = 1, right = 0 },
on_click = function()
vim.cmd("TodoTelescope")
end,
}, },
{ -- Arrow { -- Arrow
function() function()
@@ -82,11 +72,9 @@ return {
cond = function() cond = function()
return rootils.is_window_wide_enough(100) return rootils.is_window_wide_enough(100)
end, end,
}, padding = { left = 1, right = 0 },
{ -- Todo on_click = function()
todos_component, vim.cmd("Arrow open")
cond = function()
return rootils.is_window_wide_enough(100)
end, end,
}, },
}, },
@@ -100,6 +88,7 @@ return {
info = icons.diagnostics.Info, info = icons.diagnostics.Info,
hint = icons.diagnostics.Hint, hint = icons.diagnostics.Hint,
}, },
padding = { left = 0, right = 0 },
}, },
{ -- Filetype { -- Filetype
"filetype", "filetype",
@@ -107,7 +96,10 @@ return {
separator = "", separator = "",
padding = { left = 1, right = 0 }, padding = { left = 1, right = 0 },
}, },
{ LazyVim.lualine.pretty_path() }, { -- PrettyPath
LazyVim.lualine.pretty_path(),
padding = { left = 0, right = 0 },
},
}, },
lualine_x = { lualine_x = {
-- stylua: ignore -- stylua: ignore
@@ -136,6 +128,10 @@ return {
added = icons.git.added, added = icons.git.added,
modified = icons.git.modified, modified = icons.git.modified,
removed = icons.git.removed, removed = icons.git.removed,
padding = { left = 0, right = 0 },
on_click = function()
vim.cmd("LazyGit")
end,
}, },
{ -- GitSigns { -- GitSigns
source = function() source = function()
@@ -148,6 +144,13 @@ return {
} }
end end
end, end,
cond = function()
return rootils.is_window_wide_enough(200)
end,
padding = { left = 0, right = 0 },
on_click = function()
vim.cmd("LazyGit")
end,
}, },
}, },
{ -- Wakatime { -- Wakatime
@@ -160,6 +163,7 @@ return {
cond = function() cond = function()
return rootils.is_window_wide_enough(100) return rootils.is_window_wide_enough(100)
end, end,
padding = { left = 0, right = 1 },
}, },
{ -- Music { -- Music
function() function()
@@ -168,6 +172,7 @@ return {
cond = function() cond = function()
return rootils.is_window_wide_enough(100) return rootils.is_window_wide_enough(100)
end, end,
padding = { left = 0, right = 1 },
}, },
}, },
lualine_y = { lualine_y = {
@@ -179,14 +184,22 @@ return {
cond = function() cond = function()
return rootils.is_window_wide_enough(80) return rootils.is_window_wide_enough(80)
end, end,
padding = { left = 0, right = 1 },
on_click = function()
vim.cmd("Telescope current_buffer_fuzzy_find")
end,
}, },
{ -- Progress { -- Progress
"progress", "progress",
separator = " ", separator = "",
padding = { left = 1, right = 0 }, padding = { left = 0, right = 1 },
cond = function() cond = function()
return rootils.is_window_wide_enough(60) return rootils.is_window_wide_enough(60)
end, end,
icon = "",
on_click = function()
vim.cmd("Telescope grep_string")
end,
}, },
{ -- Location { -- Location
"location", "location",
@@ -194,18 +207,27 @@ return {
cond = function() cond = function()
return rootils.is_window_wide_enough(40) return rootils.is_window_wide_enough(40)
end, end,
on_click = function()
vim.cmd("Telescope grep_string")
end,
}, },
{ -- Selection { -- Selection
"selection_count", "selection_count",
cond = function() cond = function()
return rootils.is_window_wide_enough(120) return rootils.is_window_wide_enough(120)
end, end,
padding = { left = 0, right = 1 },
}, },
{ -- Filesize { -- Filesize
"filesize", "filesize",
cond = function() cond = function()
return rootils.is_window_wide_enough(100) return rootils.is_window_wide_enough(100)
end, end,
padding = { left = 0, right = 1 },
icon = "",
on_click = function()
vim.cmd("Neotree reveal toggle")
end,
}, },
}, },
lualine_z = { lualine_z = {
@@ -219,11 +241,18 @@ return {
color = "CurSearch", color = "CurSearch",
separator = { left = "", right = "" }, separator = { left = "", right = "" },
icon = "󰍉 ", icon = "󰍉 ",
on_click = function()
vim.cmd("Telescope current_buffer_fuzzy_find")
end,
}, },
{ -- Time { -- Time
"datetime", "datetime",
style = "%a %R", style = "%a %R",
icon = "", icon = "",
padding = { left = 0, right = 1 },
on_click = function()
vim.cmd("Telescope oldfiles")
end,
}, },
}, },
}, },
+25
View File
@@ -12,6 +12,31 @@ local get_fg_color = utils.get_fg_color
local set_hl = vim.api.nvim_set_hl local set_hl = vim.api.nvim_set_hl
local sign_def = vim.fn.sign_define local sign_def = vim.fn.sign_define
-- Function to apply the todo highlights
function M.apply_todo_highlights(status_string)
-- Define patterns and associated highlight groups
local patterns = {
{ icon = "", hl = "lualine_c_diagnostics_info_normal" },
{ icon = "", hl = "lualine_c_diagnostics_warning_normal" },
{ icon = "", hl = "lualine_c_diagnostics_warning_normal" },
{ icon = "", hl = "lualine_c_diagnostics_hint_normal" },
{ icon = "", hl = "lualine_c_diagnostics_hint_normal" },
}
-- Apply the highlights
for _, pattern in ipairs(patterns) do
status_string = status_string:gsub(
vim.pesc(pattern.icon),
"%#" .. pattern.hl .. "#" .. pattern.icon
)
end
-- Reset highlight to normal after the string
status_string = status_string .. "%#LualineNormal#"
return status_string
end
-- Function to set up indent highlights -- Function to set up indent highlights
function M.setup_indent_highlight() function M.setup_indent_highlight()
-- Get the background color of CursorLine -- Get the background color of CursorLine