♻️ refactor(rooticolor): move color utilities to module
Create a rooticolor module for color utilities that are used in multiple locations in config
This commit is contained in:
+10
-39
@@ -3,44 +3,15 @@
|
|||||||
-- ╰─────────────────────────────────────────────────────────╯
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- Function to convert RGB to hexadecimal
|
local rooticolor = require("utils.rooticolor")
|
||||||
local function rgb_to_hex(rgb)
|
|
||||||
return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3])
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_bg_color(hlgroup)
|
|
||||||
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
|
||||||
local bg = hl.bg
|
|
||||||
if bg then
|
|
||||||
return rgb_to_hex({
|
|
||||||
bit.rshift(bit.band(bg, 0xFF0000), 16),
|
|
||||||
bit.rshift(bit.band(bg, 0x00FF00), 8),
|
|
||||||
bit.band(bg, 0x0000FF),
|
|
||||||
})
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_fg_color(hlgroup)
|
|
||||||
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
|
||||||
local fg = hl.fg
|
|
||||||
if fg then
|
|
||||||
return rgb_to_hex({
|
|
||||||
bit.rshift(bit.band(fg, 0xFF0000), 16),
|
|
||||||
bit.rshift(bit.band(fg, 0x00FF00), 8),
|
|
||||||
bit.band(fg, 0x0000FF),
|
|
||||||
})
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
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
|
||||||
local cursorline_bg_hex = get_bg_color("CursorLine")
|
local cursorline_bg_hex = rooticolor.get_bg_color("CursorLine")
|
||||||
|
|
||||||
-- Get the foreground color of Error
|
-- Get the foreground color of Error
|
||||||
local miniiconsred_fg_hex = get_fg_color("Error")
|
local miniiconsred_fg_hex = rooticolor.get_fg_color("Error")
|
||||||
|
|
||||||
local hooks = require("ibl.hooks")
|
local hooks = require("ibl.hooks")
|
||||||
-- create the highlight groups in the highlight setup hook, so they are reset
|
-- create the highlight groups in the highlight setup hook, so they are reset
|
||||||
@@ -139,27 +110,27 @@ function M.setup_mode_highlight()
|
|||||||
local bg_color
|
local bg_color
|
||||||
|
|
||||||
if current_mode == "n" then
|
if current_mode == "n" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeNormal")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeNormal")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "v" then
|
elseif current_mode == "v" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeVisual")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeVisual")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "V" then
|
elseif current_mode == "V" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeVisual")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeVisual")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "R" or current_mode == "r" then
|
elseif current_mode == "R" or current_mode == "r" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeReplace")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeReplace")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "i" then
|
elseif current_mode == "i" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeInsert")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeInsert")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
else
|
else
|
||||||
bg_color = get_bg_color("MiniStatuslineModeNormal")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeNormal")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
end
|
end
|
||||||
@@ -167,7 +138,7 @@ end
|
|||||||
|
|
||||||
function M.setup_dashboard_highlight()
|
function M.setup_dashboard_highlight()
|
||||||
if not vim.g.DashboardHeaderColor then
|
if not vim.g.DashboardHeaderColor then
|
||||||
local dash_color = get_fg_color("Error")
|
local dash_color = rooticolor.get_fg_color("Error")
|
||||||
vim.api.nvim_set_hl(0, "DashboardHeader", { fg = dash_color })
|
vim.api.nvim_set_hl(0, "DashboardHeader", { fg = dash_color })
|
||||||
else
|
else
|
||||||
vim.api.nvim_set_hl(
|
vim.api.nvim_set_hl(
|
||||||
|
|||||||
+8
-22
@@ -3,6 +3,8 @@
|
|||||||
-- ╰─────────────────────────────────────────────────────────╯
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local rooticolor = require("utils.rooticolor")
|
||||||
|
|
||||||
local precog_first_time = true
|
local precog_first_time = true
|
||||||
|
|
||||||
-- Yank line without leading/trailing whitespace
|
-- Yank line without leading/trailing whitespace
|
||||||
@@ -67,47 +69,31 @@ end
|
|||||||
|
|
||||||
-- Set cursor icons
|
-- Set cursor icons
|
||||||
function M.set_cursor_icons()
|
function M.set_cursor_icons()
|
||||||
local function rgb_to_hex(rgb)
|
|
||||||
return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3])
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_bg_color(hlgroup)
|
|
||||||
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
|
||||||
local bg = hl.bg
|
|
||||||
if bg then
|
|
||||||
return rgb_to_hex({
|
|
||||||
bit.rshift(bit.band(bg, 0xFF0000), 16),
|
|
||||||
bit.rshift(bit.band(bg, 0x00FF00), 8),
|
|
||||||
bit.band(bg, 0x0000FF),
|
|
||||||
})
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
local current_mode = vim.fn.mode()
|
local current_mode = vim.fn.mode()
|
||||||
local bg_color
|
local bg_color
|
||||||
|
|
||||||
if current_mode == "n" then
|
if current_mode == "n" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeNormal")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeNormal")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "v" then
|
elseif current_mode == "v" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeVisual")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeVisual")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "V" then
|
elseif current_mode == "V" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeVisual")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeVisual")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "R" or current_mode == "r" then
|
elseif current_mode == "R" or current_mode == "r" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeReplace")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeReplace")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
elseif current_mode == "i" then
|
elseif current_mode == "i" then
|
||||||
bg_color = get_bg_color("MiniStatuslineModeInsert")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeInsert")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
else
|
else
|
||||||
bg_color = get_bg_color("MiniStatuslineModeNormal")
|
bg_color = rooticolor.get_bg_color("MiniStatuslineModeNormal")
|
||||||
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
vim.api.nvim_set_hl(0, "SmoothCursor", { fg = bg_color })
|
||||||
vim.fn.sign_define("smoothcursor", { text = "" })
|
vim.fn.sign_define("smoothcursor", { text = "" })
|
||||||
end
|
end
|
||||||
|
|||||||
+4
-30
@@ -1,23 +1,6 @@
|
|||||||
-- ╭─────────────────────────────────────────────────────────╮
|
-- ╭─────────────────────────────────────────────────────────╮
|
||||||
-- │ Lualine │
|
-- │ Lualine │
|
||||||
-- ╰─────────────────────────────────────────────────────────╯
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
-- Function to convert RGB to hexadecimal
|
|
||||||
local function rgb_to_hex(rgb)
|
|
||||||
return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3])
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_fg_color(hlgroup)
|
|
||||||
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
|
||||||
local fg = hl.fg
|
|
||||||
if fg then
|
|
||||||
return rgb_to_hex({
|
|
||||||
bit.rshift(bit.band(fg, 0xFF0000), 16),
|
|
||||||
bit.rshift(bit.band(fg, 0x00FF00), 8),
|
|
||||||
bit.band(fg, 0x0000FF),
|
|
||||||
})
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"nvim-lualine/lualine.nvim",
|
"nvim-lualine/lualine.nvim",
|
||||||
@@ -35,10 +18,6 @@ return {
|
|||||||
opts = function()
|
opts = function()
|
||||||
local icons = LazyVim.config.icons
|
local icons = LazyVim.config.icons
|
||||||
|
|
||||||
-- Require the dependencies
|
|
||||||
local wakatime_stats = require("config.wakatime_stats")
|
|
||||||
local music_stats = require("config.music_stats")
|
|
||||||
|
|
||||||
vim.o.laststatus = vim.g.lualine_laststatus
|
vim.o.laststatus = vim.g.lualine_laststatus
|
||||||
|
|
||||||
local opts = {
|
local opts = {
|
||||||
@@ -115,16 +94,11 @@ return {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
function()
|
function()
|
||||||
return wakatime_stats.get_icon_with_text()
|
return require("utils.wakatime_stats").get_icon_with_text()
|
||||||
end,
|
end,
|
||||||
color = function()
|
color = function()
|
||||||
if wakatime_stats.get_total_minutes() >= 60 then
|
local wakatime_stats = require("utils.wakatime_stats")
|
||||||
return { fg = get_fg_color("diffAdded") }
|
return wakatime_stats.get_color()
|
||||||
elseif wakatime_stats.get_total_minutes() >= 30 then
|
|
||||||
return { fg = get_fg_color("diffOldFile") }
|
|
||||||
else
|
|
||||||
return { fg = get_fg_color("diffRemoved") }
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
on_click = function(button)
|
on_click = function(button)
|
||||||
if button == "left" then
|
if button == "left" then
|
||||||
@@ -136,7 +110,7 @@ return {
|
|||||||
lualine_y = {
|
lualine_y = {
|
||||||
{
|
{
|
||||||
function()
|
function()
|
||||||
return music_stats.get_icon_with_text()
|
return require("utils.music_stats").get_icon_with_text()
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+2
-17
@@ -1,23 +1,8 @@
|
|||||||
-- ╭─────────────────────────────────────────────────────────╮
|
-- ╭─────────────────────────────────────────────────────────╮
|
||||||
-- │ Utilities │
|
-- │ Utilities │
|
||||||
-- ╰─────────────────────────────────────────────────────────╯
|
-- ╰─────────────────────────────────────────────────────────╯
|
||||||
-- Function to convert RGB to hexadecimal
|
|
||||||
local function rgb_to_hex(rgb)
|
|
||||||
return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3])
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_fg_color(hlgroup)
|
local rooticolor = require("utils.rooticolor")
|
||||||
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
|
||||||
local fg = hl.fg
|
|
||||||
if fg then
|
|
||||||
return rgb_to_hex({
|
|
||||||
bit.rshift(bit.band(fg, 0xFF0000), 16),
|
|
||||||
bit.rshift(bit.band(fg, 0x00FF00), 8),
|
|
||||||
bit.band(fg, 0x0000FF),
|
|
||||||
})
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{ -- Chezmoi
|
{ -- Chezmoi
|
||||||
@@ -280,7 +265,7 @@ return {
|
|||||||
table.insert(config.sections.lualine_c, {
|
table.insert(config.sections.lualine_c, {
|
||||||
git_blame.get_current_blame_text,
|
git_blame.get_current_blame_text,
|
||||||
cond = git_blame.is_blame_text_available,
|
cond = git_blame.is_blame_text_available,
|
||||||
color = { fg = get_fg_color("GitSignsCurrentLineBlame") },
|
color = { fg = rooticolor.get_fg_color("GitSignsCurrentLineBlame") },
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Apply the new configuration
|
-- Apply the new configuration
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
local bit = require("bit")
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- Function to convert RGB to hexadecimal
|
||||||
|
function M.rgb_to_hex(rgb)
|
||||||
|
return string.format("#%02x%02x%02x", rgb[1], rgb[2], rgb[3])
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Function to get the foreground color of a highlight group
|
||||||
|
function M.get_fg_color(hlgroup)
|
||||||
|
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
||||||
|
local fg = hl.fg
|
||||||
|
if fg then
|
||||||
|
return M.rgb_to_hex({
|
||||||
|
bit.rshift(bit.band(fg, 0xFF0000), 16),
|
||||||
|
bit.rshift(bit.band(fg, 0x00FF00), 8),
|
||||||
|
bit.band(fg, 0x0000FF),
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.get_bg_color(hlgroup)
|
||||||
|
local hl = vim.api.nvim_get_hl(0, { name = hlgroup, link = false })
|
||||||
|
local bg = hl.bg
|
||||||
|
if bg then
|
||||||
|
return M.rgb_to_hex({
|
||||||
|
bit.rshift(bit.band(bg, 0xFF0000), 16),
|
||||||
|
bit.rshift(bit.band(bg, 0x00FF00), 8),
|
||||||
|
bit.band(bg, 0x0000FF),
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
Reference in New Issue
Block a user