update: nvim

This commit is contained in:
2025-03-24 20:37:02 -04:00
parent ac8f51e7cf
commit cc1870ecd2
47 changed files with 880 additions and 751 deletions
+38 -16
View File
@@ -57,7 +57,7 @@ local function init_palette()
end
if not palette then
palette = vim.g.colors_name:find("catppuccin") and require("catppuccin.palettes").get_palette()
palette = (vim.g.colors_name or ""):find("catppuccin") and require("catppuccin.palettes").get_palette()
or {
rosewater = "#DC8A78",
flamingo = "#DD7878",
@@ -104,7 +104,7 @@ 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 foreground? string @The foreground color
---@param background? string @The background color
---@param italic? boolean
local function set_global_hl(name, foreground, background, italic)
@@ -133,6 +133,24 @@ function M.blend(foreground, background, alpha)
return string.format("#%02x%02x%02x", blend_channel(1), blend_channel(2), blend_channel(3))
end
---Darken a color by blending it with the background color.
---@param hex string @The color in hex to darken
---@param amount number @The amount to darken the color
---@param bg string @The background color to blend with
---@return string @The darkened color as a hex string
function M.darken(hex, amount, bg)
return M.blend(hex, bg or "#000000", math.abs(amount))
end
---Lighten a color by blending it with the foreground color.
---@param hex string @The color in hex to lighten
---@param amount number @The amount to lighten the color
---@param fg string @The foreground color to blend with
---@return string @The lightened color as a hex string
function M.lighten(hex, amount, fg)
return M.blend(hex, fg or "#FFFFFF", math.abs(amount))
end
---Get RGB highlight by highlight group
---@param hl_group string @Highlight group name
---@param use_bg boolean @Returns background or not
@@ -143,7 +161,10 @@ function M.hl_to_rgb(hl_group, use_bg, fallback_hl)
local hlexists = pcall(vim.api.nvim_get_hl, 0, { name = hl_group, link = false })
if hlexists then
local result = vim.api.nvim_get_hl(0, { name = hl_group, link = false })
-- FIXME: Investigate why hl-StatusLine is undefined in toggleterm and remove this workaround
-- (@Jint-lzxy)
local link = vim.bo.filetype == "toggleterm"
local result = vim.api.nvim_get_hl(0, { name = hl_group, link = link })
if use_bg then
hex = result.bg and string.format("#%06x", result.bg) or "NONE"
else
@@ -166,6 +187,7 @@ function M.extend_hl(name, def)
local current_def = vim.api.nvim_get_hl(0, { name = name, link = false })
local combined_def = vim.tbl_deep_extend("force", current_def, def)
---@diagnostic disable-next-line: param-type-mismatch
vim.api.nvim_set_hl(0, name, combined_def)
end
@@ -235,18 +257,13 @@ function M.gen_alpha_hl()
set_global_hl("AlphaFooter", colors.yellow)
end
-- Generate blend_color for neodim.
function M.gen_neodim_blend_attr()
local trans_bg = require("core.settings").transparent_background
local appearance = require("core.settings").background
-- Generate highlight groups for cursorword. Existing attributes will NOT be overwritten
function M.gen_cursorword_hl()
local colors = M.get_palette()
if trans_bg and appearance == "dark" then
return "#000000"
elseif trans_bg and appearance == "light" then
return "#FFFFFF"
else
return M.hl_to_rgb("Normal", true)
end
-- Do not highlight `MiniCursorwordCurrent`
set_global_hl("MiniCursorword", nil, M.darken(colors.surface1, 0.7, colors.base))
set_global_hl("MiniCursorwordCurrent", nil)
end
---Convert number (0/1) to boolean
@@ -303,7 +320,8 @@ end
---@param opts nil|table @The default config to be merged with
---@param vim_plugin? boolean @If this plugin is written in vimscript or not
---@param setup_callback? function @Add new callback if the plugin needs unusual setup function
function M.load_plugin(plugin_name, opts, vim_plugin, setup_callback)
---@param overwrite? boolean @If load user table-type config by overwriting
function M.load_plugin(plugin_name, opts, vim_plugin, setup_callback, overwrite)
vim_plugin = vim_plugin or false
-- Get the file name of the default config
@@ -336,7 +354,11 @@ function M.load_plugin(plugin_name, opts, vim_plugin, setup_callback)
if ok then
-- Extend base config if the returned user config is a table
if type(user_config) == "table" then
opts = tbl_recursive_merge(opts, user_config)
if overwrite == true then
opts = vim.tbl_deep_extend("force", opts, user_config)
else
opts = tbl_recursive_merge(opts, user_config)
end
setup_callback(opts)
-- Replace base config if the returned user config is a function
elseif type(user_config) == "function" then