From 5db0e3ee9977d788d6e9d4f2221454690367e04e Mon Sep 17 00:00:00 2001 From: siduck Date: Tue, 14 Jun 2022 17:26:29 +0530 Subject: [PATCH] allow lazy loading of highlight groups --- lua/base46/chadlights.lua | 8 +- lua/base46/init.lua | 52 ++++++-- lua/base46/integrations/alpha.lua | 6 + lua/base46/integrations/blankline.lua | 6 + .../integrations/{misc.lua => defaults.lua} | 29 ++++- lua/base46/integrations/git.lua | 30 +++++ lua/base46/integrations/gps.lua | 40 ------ lua/base46/integrations/lsp.lua | 18 +++ lua/base46/integrations/mail.lua | 35 ------ lua/base46/integrations/nvchad.lua | 114 ------------------ lua/base46/integrations/nvimtree.lua | 4 + lua/base46/integrations/telescope.lua | 12 ++ lua/base46/integrations/whichkey.lua | 9 ++ lua/base46/term.lua | 2 +- 14 files changed, 157 insertions(+), 208 deletions(-) create mode 100644 lua/base46/integrations/alpha.lua create mode 100644 lua/base46/integrations/blankline.lua rename lua/base46/integrations/{misc.lua => defaults.lua} (76%) delete mode 100644 lua/base46/integrations/gps.lua create mode 100644 lua/base46/integrations/lsp.lua delete mode 100644 lua/base46/integrations/mail.lua delete mode 100644 lua/base46/integrations/nvchad.lua create mode 100644 lua/base46/integrations/whichkey.lua diff --git a/lua/base46/chadlights.lua b/lua/base46/chadlights.lua index d1568de..6d302d3 100644 --- a/lua/base46/chadlights.lua +++ b/lua/base46/chadlights.lua @@ -1,7 +1,6 @@ -local ui = require("core.utils").load_config().ui - local merge_tb = require("base46").merge_tb +local ui = require("core.utils").load_config().ui local highlights = {} local hl_dir = vim.fn.stdpath "data" .. "/site/pack/packer/opt/base46/lua/base46/integrations" @@ -51,7 +50,4 @@ if vim.g.transparency then highlights = merge_tb(highlights, require "base46.glassy") end --- finally set all highlights :D -for hl, col in pairs(highlights) do - vim.api.nvim_set_hl(0, hl, col) -end +return highlights diff --git a/lua/base46/init.lua b/lua/base46/init.lua index 32c0ffc..c33fac2 100644 --- a/lua/base46/init.lua +++ b/lua/base46/init.lua @@ -41,23 +41,53 @@ M.clear_highlights = function(hl_group) end end -M.load_theme = function() - -- set bg option - local theme_type = M.get_theme_tb(g.nvchad_theme, "type") -- dark/light - vim.opt.bg = theme_type - +M.load_all_highlights = function() + -- reload highlights for theme switcher local reload = require("plenary.reload").reload_module local clear_hl = require("base46").clear_highlights clear_hl "BufferLine" clear_hl "TS" - -- reload highlights for theme switcher reload "base46.integrations" reload "base46.chadlights" - require "base46.term" - require "base46.chadlights" + local hl_groups = require "base46.chadlights" + + for hl, col in pairs(hl_groups) do + vim.api.nvim_set_hl(0, hl, col) + end +end + +M.load_highlight = function(group) + local default_hl = require("base46.integrations." .. group) + local user_hl = config.ui.hl_override + + if vim.g.transparency then + user_hl = M.merge_tb(user_hl, require "base46.glassy") + end + + for key, value in pairs(user_hl) do + if default_hl[key] then + default_hl[key] = value + end + end + + for hl, col in pairs(default_hl) do + vim.api.nvim_set_hl(0, hl, col) + end +end + +M.load_theme = function() + -- set bg option + local theme_type = M.get_theme_tb(g.nvchad_theme, "type") -- dark/light + vim.opt.bg = theme_type + + if vim.g.theme_switcher_loaded then + M.load_all_highlights() + end + + M.load_highlight "defaults" end M.override_theme = function(default_theme, theme_name) @@ -100,7 +130,7 @@ M.toggle_theme = function() end M.toggle_transparency = function() - local transparency_status = require("core.utils").load_config().ui.transparency + local transparency_status = config.ui.transparency local write_data = require("nvchad").write_data local function save_chadrc_data() @@ -113,12 +143,12 @@ M.toggle_transparency = function() if g.transparency then g.transparency = false - M.load_theme() + M.load_all_highlights() save_chadrc_data() else g.transparency = true - M.load_theme() + M.load_all_highlights() save_chadrc_data() end end diff --git a/lua/base46/integrations/alpha.lua b/lua/base46/integrations/alpha.lua new file mode 100644 index 0000000..9d953bd --- /dev/null +++ b/lua/base46/integrations/alpha.lua @@ -0,0 +1,6 @@ +local colors = require("base46").get_colors "base_30" + +return { + AlphaHeader = { fg = colors.grey_fg }, + AlphaButtons = { fg = colors.light_grey }, +} diff --git a/lua/base46/integrations/blankline.lua b/lua/base46/integrations/blankline.lua new file mode 100644 index 0000000..8972616 --- /dev/null +++ b/lua/base46/integrations/blankline.lua @@ -0,0 +1,6 @@ +local colors = require("base46").get_colors "base_30" + +return { + IndentBlanklineChar = { fg = colors.line }, + IndentBlanklineSpaceChar = { fg = colors.line }, +} diff --git a/lua/base46/integrations/misc.lua b/lua/base46/integrations/defaults.lua similarity index 76% rename from lua/base46/integrations/misc.lua rename to lua/base46/integrations/defaults.lua index cdb5052..5857ad4 100644 --- a/lua/base46/integrations/misc.lua +++ b/lua/base46/integrations/defaults.lua @@ -1,6 +1,34 @@ +local colors = require("base46").get_colors "base_30" local theme = require("base46").get_colors "base_16" return { + MatchWord = { + bg = colors.grey, + fg = colors.white, + }, + + Pmenu = { bg = colors.one_bg }, + PmenuSbar = { bg = colors.one_bg }, + PmenuSel = { bg = colors.pmenu_bg, fg = colors.black }, + PmenuThumb = { bg = colors.grey }, + + MatchParen = { link = "MatchWord" }, + + Comment = { fg = colors.grey_fg }, + + CursorLineNr = { fg = colors.white }, + LineNr = { fg = colors.grey }, + + -- floating windows + FloatBorder = { fg = colors.blue }, + NormalFloat = { bg = colors.darker_black }, + + NvimInternalError = { fg = colors.red }, + WinSeparator = { fg = colors.line }, + + -- packer + packerPackageName = { fg = colors.red }, + Normal = { fg = theme.base05, bg = theme.base00, @@ -151,7 +179,6 @@ return { }, -- spell - SpellBad = { undercurl = true, sp = theme.base08, diff --git a/lua/base46/integrations/git.lua b/lua/base46/integrations/git.lua index 7c947bd..003b78e 100644 --- a/lua/base46/integrations/git.lua +++ b/lua/base46/integrations/git.lua @@ -1,4 +1,5 @@ local theme = require("base46").get_colors "base_16" +local colors = require("base46").get_colors "base_30" return { @@ -66,4 +67,33 @@ return { fg = theme.base0B, bold = true, }, + + -- Gitsigns.nvim + DiffAdd = { + fg = colors.blue, + }, + + DiffAdded = { + fg = colors.green, + }, + + DiffChange = { + fg = colors.light_grey, + }, + + DiffChangeDelete = { + fg = colors.red, + }, + + DiffModified = { + fg = colors.orange, + }, + + DiffDelete = { + fg = colors.red, + }, + + DiffRemoved = { + fg = colors.red, + }, } diff --git a/lua/base46/integrations/gps.lua b/lua/base46/integrations/gps.lua deleted file mode 100644 index 26ccb8e..0000000 --- a/lua/base46/integrations/gps.lua +++ /dev/null @@ -1,40 +0,0 @@ -local base16 = require("base46").get_colors "base_16" -local colors = require("base46").get_colors "base_30" - -return { - -- nvim Gps - GpsItemAbbr = { fg = colors.white, bg = colors.statusline_bg, bold = true }, - GpsItemAbbrMatch = { fg = colors.blue, bold = true, bg = colors.statusline_bg }, - GpsBorder = { fg = colors.grey, bg = colors.statusline_bg, bold = true }, - GpsDocBorder = { fg = colors.grey, bg = colors.statusline_bg, bold = true }, - - -- Gps item kinds - GpsItemKindConstant = { fg = base16.base09, bg = colors.statusline_bg, bold = true }, - GpsItemKindFunction = { fg = base16.base0D, bg = colors.statusline_bg, bold = true }, - GpsItemKindIdentifier = { fg = base16.base08, bg = colors.statusline_bg, bold = true }, - GpsItemKindField = { fg = base16.base08, bg = colors.statusline_bg, bold = true }, - GpsItemKindVariable = { fg = base16.base0E, bg = colors.statusline_bg, bold = true }, - GpsItemKindSnippet = { fg = colors.red, bg = colors.statusline_bg, bold = true }, - GpsItemKindText = { fg = base16.base0B, bg = colors.statusline_bg, bold = true }, - GpsItemKindStructure = { fg = base16.base0E, bg = colors.statusline_bg, bold = true }, - GpsItemKindType = { fg = base16.base0A, bg = colors.statusline_bg, bold = true }, - GpsItemKindKeyword = { fg = base16.base07, bg = colors.statusline_bg, bold = true }, - GpsItemKindMethod = { fg = base16.base0D, bg = colors.statusline_bg, bold = true }, - GpsItemKindConstructor = { fg = colors.blue, bg = colors.statusline_bg, bold = true }, - GpsItemKindFolder = { fg = base16.base07, bg = colors.statusline_bg, bold = true }, - GpsItemKindModule = { fg = base16.base0A, bg = colors.statusline_bg, bold = true }, - GpsItemKindProperty = { fg = base16.base08, bg = colors.statusline_bg, bold = true }, - -- GpsItemKindEnum = { fg = "", bg = colors.statusline_bg, bold = true}, - GpsItemKindUnit = { fg = base16.base0E, bg = colors.statusline_bg, bold = true }, - -- GpsItemKindClass = { fg = "", bg = colors.statusline_bg, bold = true}, - GpsItemKindFile = { fg = base16.base07, bg = colors.statusline_bg, bold = true }, - -- GpsItemKindInterface = { fg = "", bg = colors.statusline_bg, bold = true}, - GpsItemKindColor = { fg = colors.red, bg = colors.statusline_bg, bold = true }, - GpsItemKindReference = { fg = base16.base05, bg = colors.statusline_bg, bold = true }, - -- GpsItemKindEnumMember = { fg = "", bg = colors.statusline_bg, bold = true}, - GpsItemKindStruct = { fg = base16.base0E, bg = colors.statusline_bg, bold = true }, - -- GpsItemKindValue = { fg = "", bg = colors.statusline_bg, bold = true}, - -- GpsItemKindEvent = { fg = "", bg = colors.statusline_bg, bold = true}, - GpsItemKindOperator = { fg = base16.base05, bg = colors.statusline_bg, bold = true }, - GpsItemKindTypeParameter = { fg = base16.base08, bg = colors.statusline_bg, bold = true }, -} diff --git a/lua/base46/integrations/lsp.lua b/lua/base46/integrations/lsp.lua new file mode 100644 index 0000000..90d8d50 --- /dev/null +++ b/lua/base46/integrations/lsp.lua @@ -0,0 +1,18 @@ +local colors = require("base46").get_colors "base_30" + +return { + -- LSP References + LspReferenceText = { fg = colors.darker_black, bg = colors.white }, + LspReferenceRead = { fg = colors.darker_black, bg = colors.white }, + LspReferenceWrite = { fg = colors.darker_black, bg = colors.white }, + + -- Lsp Diagnostics + DiagnosticHint = { fg = colors.purple }, + DiagnosticError = { fg = colors.red }, + DiagnosticWarn = { fg = colors.yellow }, + DiagnosticInformation = { fg = colors.green }, + LspSignatureActiveParameter = { fg = colors.black, bg = colors.green }, + + RenamerTitle = { fg = colors.black, bg = colors.red }, + RenamerBorder = { fg = colors.red }, +} diff --git a/lua/base46/integrations/mail.lua b/lua/base46/integrations/mail.lua deleted file mode 100644 index 77b3022..0000000 --- a/lua/base46/integrations/mail.lua +++ /dev/null @@ -1,35 +0,0 @@ -local theme = require("base46").get_colors "base_16" - -return { - mailQuoted1 = { - fg = theme.base0A, - }, - - mailQuoted2 = { - fg = theme.base0B, - }, - - mailQuoted3 = { - fg = theme.base0E, - }, - - mailQuoted4 = { - fg = theme.base0C, - }, - - mailQuoted5 = { - fg = theme.base0D, - }, - - mailQuoted6 = { - fg = theme.base0A, - }, - - mailURL = { - fg = theme.base0D, - }, - - mailEmail = { - fg = theme.base0D, - }, -} diff --git a/lua/base46/integrations/nvchad.lua b/lua/base46/integrations/nvchad.lua deleted file mode 100644 index c1ee276..0000000 --- a/lua/base46/integrations/nvchad.lua +++ /dev/null @@ -1,114 +0,0 @@ -local colors = require("base46").get_colors "base_30" - -local black = colors.black -local blue = colors.blue -local darker_black = colors.darker_black -local green = colors.green -local grey = colors.grey -local grey_fg = colors.grey_fg -local light_grey = colors.light_grey -local line = colors.line -local one_bg = colors.one_bg -local pmenu_bg = colors.pmenu_bg -local purple = colors.purple -local red = colors.red -local white = colors.white -local yellow = colors.yellow -local orange = colors.orange - --- highlight groups & colors -return { - - Comment = { fg = grey_fg }, - - -- line numbers - CursorLineNr = { fg = white }, - LineNr = { fg = grey }, - - -- those ugly ~'s - EndOfBuffer = { fg = black }, - - -- floating windows - FloatBorder = { fg = blue }, - NormalFloat = { bg = darker_black }, - - -- Renamer - - RenamerTitle = { fg = black, bg = red }, - RenamerBorder = { fg = red }, - - -- Pmenu i.e completion menu - Pmenu = { bg = one_bg }, - PmenuSbar = { bg = one_bg }, - PmenuSel = { bg = pmenu_bg, fg = black }, - PmenuThumb = { bg = grey }, - - NvimInternalError = { fg = red }, - WinSeparator = { fg = line }, - - -- Dashboard i.e alpha.nvim - AlphaHeader = { fg = grey_fg }, - AlphaButtons = { fg = light_grey }, - - -- Gitsigns.nvim - DiffAdd = { - fg = blue, - }, - - DiffAdded = { - fg = green, - }, - - DiffChange = { - fg = light_grey, - }, - - DiffChangeDelete = { - fg = red, - }, - - DiffModified = { - fg = orange, - }, - - DiffDelete = { - fg = red, - }, - - DiffRemoved = { - fg = red, - }, - - -- Indent blankline - IndentBlanklineChar = { fg = line }, - IndentBlanklineSpaceChar = { fg = line }, - - -- LSP References - LspReferenceText = { fg = darker_black, bg = white }, - LspReferenceRead = { fg = darker_black, bg = white }, - LspReferenceWrite = { fg = darker_black, bg = white }, - - -- Lsp Diagnostics - DiagnosticHint = { fg = purple }, - DiagnosticError = { fg = red }, - DiagnosticWarn = { fg = yellow }, - DiagnosticInformation = { fg = green }, - - -- whichkey - WhichKey = { fg = blue }, - WhichKeySeparator = { fg = light_grey }, - WhichKeyDesc = { fg = red }, - WhichKeyGroup = { fg = green }, - WhichKeyValue = { fg = green }, - - -- packer - packerPackageName = { fg = red }, - - -- vim-matchup - MatchWord = { - bg = grey, - fg = white, - }, - - MatchParen = { link = "MatchWord" }, -} diff --git a/lua/base46/integrations/nvimtree.lua b/lua/base46/integrations/nvimtree.lua index 38fb835..a5ace84 100644 --- a/lua/base46/integrations/nvimtree.lua +++ b/lua/base46/integrations/nvimtree.lua @@ -25,4 +25,8 @@ return { NvimTreeCursorLine = { bg = colors.black2, }, + + NvimTreeGitNew = { + fg = colors.yellow, + }, } diff --git a/lua/base46/integrations/telescope.lua b/lua/base46/integrations/telescope.lua index feee0de..9155cb8 100644 --- a/lua/base46/integrations/telescope.lua +++ b/lua/base46/integrations/telescope.lua @@ -40,4 +40,16 @@ return { }, TelescopeSelection = { bg = colors.black2, fg = colors.white }, + + TelescopeResultsDiffAdd = { + fg = colors.green, + }, + + TelescopeResultsDiffChange = { + fg = colors.yellow, + }, + + TelescopeResultsDiffDelete = { + fg = colors.red, + }, } diff --git a/lua/base46/integrations/whichkey.lua b/lua/base46/integrations/whichkey.lua new file mode 100644 index 0000000..a2e5752 --- /dev/null +++ b/lua/base46/integrations/whichkey.lua @@ -0,0 +1,9 @@ +local colors = require("base46").get_colors "base_30" + +return { + WhichKey = { fg = colors.blue }, + WhichKeySeparator = { fg = colors.light_grey }, + WhichKeyDesc = { fg = colors.red }, + WhichKeyGroup = { fg = colors.green }, + WhichKeyValue = { fg = colors.green }, +} diff --git a/lua/base46/term.lua b/lua/base46/term.lua index 79cc970..5d9060c 100644 --- a/lua/base46/term.lua +++ b/lua/base46/term.lua @@ -1,6 +1,6 @@ local colors = require("base46").get_colors "base_16" -vim.g.terminal_color_0 = colors.base00 +vim.g.terminal_color_0 = colors.base02 vim.g.terminal_color_1 = colors.base08 vim.g.terminal_color_2 = colors.base0B vim.g.terminal_color_3 = colors.base0A