Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _G._flash_esc_or_noh = function()
if flash_active and state then
state:hide()
else
vim.cmd([[noh]])
pcall(vim.cmd.noh)
end
end

Expand Down
6 changes: 4 additions & 2 deletions lua/modules/configs/ui/catppuccin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ return function()
local clear = {}

require("modules.utils").load_plugin("catppuccin", {
flavour = "mocha", -- Can be one of: latte, frappe, macchiato, mocha
background = { light = "latte", dark = "mocha" },
background = { light = "latte", dark = "mocha" }, -- latte, frappe, macchiato, mocha
dim_inactive = {
enabled = false,
-- Dim inactive splits/windows/buffers.
Expand Down Expand Up @@ -138,6 +137,9 @@ return function()
FidgetTask = { bg = cp.none, fg = cp.surface2 },
FidgetTitle = { fg = cp.blue, style = { "bold" } },

-- For nvim-notify
NotifyBackground = { bg = cp.base },

-- For nvim-tree
NvimTreeRootFolder = { fg = cp.pink },
NvimTreeIndentMarker = { fg = cp.surface2 },
Expand Down
3 changes: 1 addition & 2 deletions lua/modules/configs/ui/notify.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
return function()
local notify = require("notify")
local colors = require("modules.utils").get_palette()
local icons = {
diagnostics = require("modules.utils.icons").get("diagnostics"),
ui = require("modules.utils.icons").get("ui"),
Expand All @@ -23,7 +22,7 @@ return function()
-- Render function for notifications. See notify-render()
render = "default",
---@usage highlight behind the window for stages that change opacity
background_colour = colors.base,
background_colour = "NotifyBackground",
---@usage minimum width for notification windows
minimum_width = 50,
---@usage notifications with level lower than this would be ignored. [ERROR > WARN > INFO > DEBUG > TRACE]
Expand Down
41 changes: 30 additions & 11 deletions lua/modules/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ local function init_palette()
callback = function()
palette = nil
init_palette()
-- Also refresh hard-coded hl groups
M.gen_alpha_hl()
M.gen_lspkind_hl()
pcall(vim.cmd.AlphaRedraw)
end,
})
end
Expand Down Expand Up @@ -92,27 +96,42 @@ local function init_palette()
end

---@param c string @The color in hexadecimal.
local function hexToRgb(c)
local function hex_to_rgb(c)
c = string.lower(c)
return { tonumber(c:sub(2, 3), 16), tonumber(c:sub(4, 5), 16), tonumber(c:sub(6, 7), 16) }
end

-- NOTE: If the active colorscheme isn't `catppuccin`, this function won't overwrite existing definitions
---Sets a global highlight group.
---@param name string @Highlight group name, e.g. "ErrorMsg"
---@param foreground string @The foreground color
---@param background? string @The background color
---@param italic? boolean
local function set_global_hl(name, foreground, background, italic)
vim.api.nvim_set_hl(0, name, {
fg = foreground,
bg = background,
italic = italic == true,
default = not vim.g.colors_name:find("catppuccin"),
})
end

---Blend foreground with background
---@param foreground string @The foreground color
---@param background string @The background color to blend with
---@param alpha number|string @Number between 0 and 1 for blending amount.
function M.blend(foreground, background, alpha)
---@diagnostic disable-next-line: cast-local-type
alpha = type(alpha) == "string" and (tonumber(alpha, 16) / 0xff) or alpha
local bg = hexToRgb(background)
local fg = hexToRgb(foreground)
local bg = hex_to_rgb(background)
local fg = hex_to_rgb(foreground)

local blendChannel = function(i)
local blend_channel = function(i)
local ret = (alpha * fg[i] + ((1 - alpha) * bg[i]))
return math.floor(math.min(math.max(0, ret), 255) + 0.5)
end

return string.format("#%02x%02x%02x", blendChannel(1), blendChannel(2), blendChannel(3))
return string.format("#%02x%02x%02x", blend_channel(1), blend_channel(2), blend_channel(3))
end

---Get RGB highlight by highlight group
Expand Down Expand Up @@ -156,7 +175,7 @@ end
---@return palette
function M.get_palette(overwrite)
if not overwrite then
return init_palette()
return vim.deepcopy(init_palette())
else
return vim.tbl_extend("force", init_palette(), overwrite)
end
Expand Down Expand Up @@ -203,18 +222,18 @@ function M.gen_lspkind_hl()
}

for kind, color in pairs(dat) do
vim.api.nvim_set_hl(0, "LspKind" .. kind, { fg = color, default = true })
set_global_hl("LspKind" .. kind, color)
end
end

-- Generate highlight groups for alpha. Existing attributes will NOT be overwritten
function M.gen_alpha_hl()
local colors = M.get_palette()

vim.api.nvim_set_hl(0, "AlphaHeader", { fg = colors.blue, default = true })
vim.api.nvim_set_hl(0, "AlphaButtons", { fg = colors.green, default = true })
vim.api.nvim_set_hl(0, "AlphaShortcut", { fg = colors.pink, italic = true, default = true })
vim.api.nvim_set_hl(0, "AlphaFooter", { fg = colors.yellow, default = true })
set_global_hl("AlphaHeader", colors.blue)
set_global_hl("AlphaButtons", colors.green)
set_global_hl("AlphaShortcut", colors.pink, nil, true)
set_global_hl("AlphaFooter", colors.yellow)
end

-- Generate blend_color for neodim.
Expand Down