diff --git a/nvim/lua/colors.lua b/nvim/lua/colors.lua deleted file mode 100644 index 4f91a12..0000000 --- a/nvim/lua/colors.lua +++ /dev/null @@ -1,16 +0,0 @@ -local has_generated = false -local colors = require("ayu.colors") -colors.generate(true) - -local M = {} - -function M.get() - if not has_generated then - colors.generate(true) - has_generated = true - end - - return colors -end - -return M diff --git a/nvim/lua/diagnostics.lua b/nvim/lua/diagnostics.lua index 37e77c1..d5def0a 100644 --- a/nvim/lua/diagnostics.lua +++ b/nvim/lua/diagnostics.lua @@ -1,30 +1,35 @@ -local theme_colors = require("ayu.colors") -theme_colors.generate(true) --- These are not apart of the Ayu color theme, however, I needed these --- colors while still fitting in with the rest -local ayu_turquoise = "#5CCFE6" -local ayu_dark_blue = "#3A7BD5" +local utils = require("utils") -local colors = { - info = ayu_dark_blue, - hint = ayu_turquoise, - warning = theme_colors.warning, - error = theme_colors.error, -} +local function setup_colors() + -- These are not apart of the Ayu color theme, however, I needed these + -- colors while still fitting in with the rest + local ayu_turquoise = "#5CCFE6" + local ayu_dark_blue = "#3A7BD5" -for _, highlight in ipairs({ - { "DiagnosticUnderlineInfo", { undercurl = true, sp = colors.info } }, - { "DiagnosticUnderlineHint", { undercurl = true, sp = colors.hint } }, - { "DiagnosticUnderlineWarn", { undercurl = true, sp = colors.warning } }, - { "DiagnosticUnderlineError", { undercurl = true, sp = colors.error } }, - { "DiagnosticInfo", { fg = colors.info } }, - { "DiagnosticHint", { fg = colors.hint } }, - { "DiagnosticWarn", { fg = colors.warning } }, - { "DiagnosticError", { fg = colors.error } }, -}) do - vim.api.nvim_set_hl(0, highlight[1], highlight[2]) + local colors = { + info = ayu_dark_blue, + hint = ayu_turquoise, + warning = utils.ayu_colors.warning, + error = utils.ayu_colors.error, + } + + for _, highlight in ipairs({ + { "DiagnosticUnderlineInfo", { undercurl = true, sp = colors.info } }, + { "DiagnosticUnderlineHint", { undercurl = true, sp = colors.hint } }, + { "DiagnosticUnderlineWarn", { undercurl = true, sp = colors.warning } }, + { "DiagnosticUnderlineError", { undercurl = true, sp = colors.error } }, + { "DiagnosticInfo", { fg = colors.info } }, + { "DiagnosticHint", { fg = colors.hint } }, + { "DiagnosticWarn", { fg = colors.warning } }, + { "DiagnosticError", { fg = colors.error } }, + }) do + vim.api.nvim_set_hl(0, highlight[1], highlight[2]) + end end +utils.create_user_event_cb("ColorsyncThemeChanged", setup_colors, "ColorsyncEvents") +setup_colors() + local sev = vim.diagnostic.severity vim.diagnostic.config({ underline = true, diff --git a/nvim/lua/plugs/ayu.lua b/nvim/lua/plugs/ayu.lua index f9a1615..11a9ae2 100644 --- a/nvim/lua/plugs/ayu.lua +++ b/nvim/lua/plugs/ayu.lua @@ -1,5 +1,5 @@ local uv = vim.loop -local api = vim.api +local utils = require("utils") local function force_color_from_reference_on_others(others, reference) local reference_hl = vim.api.nvim_get_hl(0, { name = reference }) @@ -28,104 +28,109 @@ end return { "Shatur/neovim-ayu", + priority = 1010, config = function() - local ayu = require("ayu") - local colors = require("ayu.colors") - colors.generate(true) - - local overrides = { - global_variable = { - underline = true, - italic = true, - }, - member_variable = { - bold = true, - }, - namespace = { - italic = true, - fg = colors.markup, - }, - pre_process = { - fg = colors.keyword, - }, - default_type = { - fg = colors.regexp - }, - type = { - fg = colors.entity, - }, - } - - ayu.setup({ - mirage = true, - terminal = false, - overrides = { - -- TRANSPARENCY - -- Normal = { bg = "none" }, - -- NormalFloat = { bg = "none" }, - -- ColorColumn = { bg = "none" }, - -- SignColumn = { bg = "none" }, - -- Folded = { bg = "none" }, - -- FoldColumn = { bg = "none" }, - -- CursorColumn = { bg = "none" }, - -- VertSplit = { bg = "none" }, - -- TRANSPARENCY - CursorLineNr = { bg = "none" }, - ["@property"] = overrides.member_variable, - ["PreProc"] = overrides.pre_process, - --CPP - ["@lsp.typemod.variable.fileScope.cpp"] = overrides.global_variable, - ["@lsp.type.namespace.cpp"] = overrides.namespace, - ["@type.builtin.cpp"] = overrides.default_type, - -- CPP - -- - -- Rust - ["@lsp.type.struct.rust"] = overrides.type, - ["@lsp.type.namespace.rust"] = overrides.namespace, - ["@lsp.type.builtinType.rust"] = overrides.default_type, - -- Rust - -- - -- C - ["@lsp.typemod.variable.globalScope.c"] = overrides.global_variable, - ["@type.builtin.c"] = overrides.default_type, - -- C - -- - -- Go - -- ["@module.go"] = overrides.namespace, -- The go LSP is not reliable enough for this sadly, sometimes it adds module tokens and sometimes it doesnt. - ["@variable.member.go"] = overrides.member_variable, - ["@type.builtin.go"] = overrides.default_type, - -- Go - -- - -- Zig - ["@module.zig"] = overrides.namespace, - ["@type.builtin.zig"] = overrides.default_type, - ["@function.builtin.zig"] = overrides.default_type, - -- ["@variable.member.zig"] = overrides.member_variable,-- Cant have bold member variable in zig, they don't differentiate function calls/accessors from variables, they are all just "members" .... BS LSP - -- ["@variable.parameter"] = {},-- Zig LSP is lacking, a parameter is marked as a regular variable outside of it's definition, can't separate between them. - -- Zig - }, - }) - local function set_colorscheme() - local active_theme = vim.fn.system({ "colorsync", "get" }):gsub("%s+", "") - if active_theme == "ayulight" then - api.nvim_command("colorscheme ayu-light") - elseif active_theme == "ayumirage" then - api.nvim_command("colorscheme ayu-mirage") - else - api.nvim_command("colorscheme ayu-dark") - end + utils.colorsync_theme = vim.fn.system({ "colorsync", "get" }):gsub("%s+", "") + vim.o.background = utils.colorsync_theme == "ayulight" and "light" or "dark" + + local is_mirage = utils.colorsync_theme == "ayumirage" + + local ayu = require("ayu") + utils.ayu_colors = require("ayu.colors") + utils.ayu_colors.generate(is_mirage) + + local overrides = { + global_variable = { + underline = true, + italic = true, + }, + member_variable = { + bold = true, + }, + namespace = { + italic = true, + fg = utils.ayu_colors.markup, + }, + pre_process = { + fg = utils.ayu_colors.keyword, + }, + default_type = { + fg = utils.ayu_colors.regexp + }, + type = { + fg = utils.ayu_colors.entity, + }, + } + + ayu.setup({ + mirage = is_mirage, + terminal = false, + overrides = { + -- TRANSPARENCY + -- Normal = { bg = "none" }, + -- NormalFloat = { bg = "none" }, + -- ColorColumn = { bg = "none" }, + -- SignColumn = { bg = "none" }, + -- Folded = { bg = "none" }, + -- FoldColumn = { bg = "none" }, + -- CursorColumn = { bg = "none" }, + -- VertSplit = { bg = "none" }, + -- TRANSPARENCY + CursorLineNr = { bg = "none" }, + ["@property"] = overrides.member_variable, + ["PreProc"] = overrides.pre_process, + --CPP + ["@lsp.typemod.variable.fileScope.cpp"] = overrides.global_variable, + ["@lsp.type.namespace.cpp"] = overrides.namespace, + ["@type.builtin.cpp"] = overrides.default_type, + -- CPP + -- + -- Rust + ["@lsp.type.struct.rust"] = overrides.type, + ["@lsp.type.namespace.rust"] = overrides.namespace, + ["@lsp.type.builtinType.rust"] = overrides.default_type, + -- Rust + -- + -- C + ["@lsp.typemod.variable.globalScope.c"] = overrides.global_variable, + ["@type.builtin.c"] = overrides.default_type, + -- C + -- + -- Go + -- ["@module.go"] = overrides.namespace, -- The go LSP is not reliable enough for this sadly, sometimes it adds module tokens and sometimes it doesnt. + ["@variable.member.go"] = overrides.member_variable, + ["@type.builtin.go"] = overrides.default_type, + -- Go + -- + -- Zig + ["@module.zig"] = overrides.namespace, + ["@type.builtin.zig"] = overrides.default_type, + ["@function.builtin.zig"] = overrides.default_type, + -- ["@variable.member.zig"] = overrides.member_variable,-- Cant have bold member variable in zig, they don't differentiate function calls/accessors from variables, they are all just "members" .... BS LSP + -- ["@variable.parameter"] = {},-- Zig LSP is lacking, a parameter is marked as a regular variable outside of it's definition, can't separate between them. + -- Zig + }, + }) + + ayu.colorscheme() end + vim.api.nvim_create_augroup("ColorsyncEvents", { clear = true }) + local filepath = os.getenv("HOME") .. "/.local/state/colorsync/current" local handle = uv.new_fs_event() - handle:start(filepath, {}, function(err, filename, status) + handle:start(filepath, {}, function(err) if err then vim.notify("Error watching: " .. filepath .. "\n" .. err) return end - vim.schedule(set_colorscheme) + vim.schedule(function() + set_colorscheme() + vim.api.nvim_exec_autocmds("User", { pattern = "ColorsyncThemeChanged" }) + vim.api.nvim_exec_autocmds("ColorScheme", {}) + end) end) set_colorscheme() diff --git a/nvim/lua/plugs/incline.lua b/nvim/lua/plugs/incline.lua index 0b92758..f0359e8 100644 --- a/nvim/lua/plugs/incline.lua +++ b/nvim/lua/plugs/incline.lua @@ -1,3 +1,5 @@ +local utils = require("utils") + return { "b0o/incline.nvim", dependencies = { @@ -10,111 +12,116 @@ return { } } }, - event = "VeryLazy", - lazy = true, - opts = { - window = { - padding = 0, - }, - hide = { - cursorline = false, - }, - render = function(props) - local fullpath = vim.api.nvim_buf_get_name(props.buf) - local filename = vim.fn.fnamemodify(fullpath, ":t") - if filename == "" then - filename = "[No Name]" - end - - local function get_ft_icon() - local ft_icon, ft_color = require("nvim-web-devicons").get_icon_color(filename) - return { (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" } - end - - local function get_file_path() - local path_display = "" - if fullpath == "" then - path_display = filename - else - local parts = {} - for part in string.gmatch(vim.fn.fnamemodify(fullpath, ":.:h"), "[^/]+") do - table.insert(parts, part) + config = function() + local function setup_incline() + require("incline").setup({ + window = { + padding = 0, + }, + hide = { + cursorline = false, + }, + render = function(props) + local fullpath = vim.api.nvim_buf_get_name(props.buf) + local filename = vim.fn.fnamemodify(fullpath, ":t") + if filename == "" then + filename = "[No Name]" end - local ellipsis = "…" - local max_path_parts = 2 - if #parts > max_path_parts then - local start_index = #parts - max_path_parts + 1 - path_display = ellipsis .. "/" .. table.concat(parts, "/", start_index) - elseif #parts > 0 then - path_display = table.concat(parts, "/") + local function get_ft_icon() + local ft_icon, ft_color = require("nvim-web-devicons").get_icon_color(filename) + return { (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" } end - if path_display ~= "" then - path_display = path_display .. "/" .. filename - else - path_display = filename + local function get_file_path() + local path_display = "" + if fullpath == "" then + path_display = filename + else + local parts = {} + for part in string.gmatch(vim.fn.fnamemodify(fullpath, ":.:h"), "[^/]+") do + table.insert(parts, part) + end + + local ellipsis = "…" + local max_path_parts = 2 + if #parts > max_path_parts then + local start_index = #parts - max_path_parts + 1 + path_display = ellipsis .. "/" .. table.concat(parts, "/", start_index) + elseif #parts > 0 then + path_display = table.concat(parts, "/") + end + + if path_display ~= "" then + path_display = path_display .. "/" .. filename + else + path_display = filename + end + end + + return { path_display .. " ┊", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" } end - end - return { path_display .. " ┊", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" } - end - - local function get_git_diff() - local icons = { removed = "", changed = "", added = "" } - local signs = vim.b[props.buf].gitsigns_status_dict - local labels = {} - if signs == nil then - return labels - end - for name, icon in pairs(icons) do - if tonumber(signs[name]) and signs[name] > 0 then - table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name }) + local function get_git_diff() + local icons = { removed = "", changed = "", added = "" } + local signs = vim.b[props.buf].gitsigns_status_dict + local labels = {} + if signs == nil then + return labels + end + for name, icon in pairs(icons) do + if tonumber(signs[name]) and signs[name] > 0 then + table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name }) + end + end + if #labels > 0 then + table.insert(labels, { "┊ " }) + end + return labels end - end - if #labels > 0 then - table.insert(labels, { "┊ " }) - end - return labels - end - local function get_diagnostic_label() - local icons = { error = "", warn = "", info = "", hint = "" } - local label = {} + local function get_diagnostic_label() + local icons = { error = "", warn = "", info = "", hint = "" } + local label = {} - for severity, icon in pairs(icons) do - local n = #vim.diagnostic.get(props.buf, - { severity = vim.diagnostic.severity[string.upper(severity)] }) - if n > 0 then - table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity }) + for severity, icon in pairs(icons) do + local n = #vim.diagnostic.get(props.buf, + { severity = vim.diagnostic.severity[string.upper(severity)] }) + if n > 0 then + table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity }) + end + end + if #label > 0 then + table.insert(label, { "┊ " }) + end + return label end - end - if #label > 0 then - table.insert(label, { "┊ " }) - end - return label - end - local function get_arrow_label() - local statusline = require("arrow.statusline") - if statusline.is_on_arrow_file(props.buf) == nil then - return "" - end + local function get_arrow_label() + local statusline = require("arrow.statusline") + if statusline.is_on_arrow_file(props.buf) == nil then + return "" + end - return " " .. statusline.text_for_statusline_with_icons(props.buf) - end + return " " .. statusline.text_for_statusline_with_icons(props.buf) + end - return { - guibg = "#1e2030", - guifg = "#cad3f5", - { " " }, - { get_diagnostic_label() }, - { get_git_diff() }, - { get_ft_icon() }, - { get_file_path() }, - { get_arrow_label() .. "  " .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" }, - { " " } - } - end, - }, + return { + guibg = utils.ayu_colors.panel_bg, + guifg = utils.ayu_colors.fg, + { " " }, + { get_diagnostic_label() }, + { get_git_diff() }, + { get_ft_icon() }, + { get_file_path() }, + { get_arrow_label() .. "  " .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" }, + { " " } + } + end, + }) + end + + utils.create_user_event_cb("ColorsyncThemeChanged", setup_incline, "ColorsyncEvents") + setup_incline() + end } diff --git a/nvim/lua/plugs/leap.lua b/nvim/lua/plugs/leap.lua index 5c1b8d2..babe2f1 100644 --- a/nvim/lua/plugs/leap.lua +++ b/nvim/lua/plugs/leap.lua @@ -1,3 +1,5 @@ +local utils = require("utils") + local saved_hlsearch = false local saved_highlights = {} @@ -23,7 +25,7 @@ end local function save_and_set_invisible_inlay_hints_hl() saved_highlights = vim.api.nvim_get_hl(0, { name = "LspInlayHint" }) - vim.api.nvim_set_hl(0, "LspInlayHint", { fg = require("colors").get().bg, bg = "none" }) + vim.api.nvim_set_hl(0, "LspInlayHint", { fg = utils.ayu_colors.bg, bg = "none" }) end local function restore_inlay_hints_hl() diff --git a/nvim/lua/plugs/lualine.lua b/nvim/lua/plugs/lualine.lua index 6b2a849..6788ef7 100644 --- a/nvim/lua/plugs/lualine.lua +++ b/nvim/lua/plugs/lualine.lua @@ -1,3 +1,5 @@ +local utils = require("utils") + local function resize_mode() if require("window_management").is_in_resizing_mode() then return "▲ Resizing ▼ " @@ -26,45 +28,52 @@ return { }, event = "VeryLazy", lazy = true, - opts = { - options = { - theme = "ayu", - globalstatus = true, - section_separators = { - left = "", - right = "", - }, - component_separators = { - left = "", - right = "" - }, - icons_enabled = true, - }, - sections = { - lualine_a = { "mode" }, - lualine_b = { - "branch", - { - "diagnostics", - sources = { "nvim_lsp" }, - sections = { "error", "warn", "info", "hint" }, - update_in_insert = false, + config = function() + local function setup_lualine() + require("lualine").setup({ + options = { + theme = "ayu", + globalstatus = true, + section_separators = { + left = "", + right = "", + }, + component_separators = { + left = "", + right = "" + }, + icons_enabled = true, }, - resize_mode, - }, - lualine_c = { tabs }, - lualine_x = { "encoding", "fileformat", "filetype" }, - lualine_y = { "progress" }, - lualine_z = { "location" } - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {}, - lualine_x = {}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - } + sections = { + lualine_a = { "mode" }, + lualine_b = { + "branch", + { + "diagnostics", + sources = { "nvim_lsp" }, + sections = { "error", "warn", "info", "hint" }, + update_in_insert = false, + }, + resize_mode, + }, + lualine_c = { tabs }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + }) + end + + utils.create_user_event_cb("ColorsyncThemeChanged", setup_lualine, "ColorsyncEvents") + setup_lualine() + end } diff --git a/nvim/lua/utils.lua b/nvim/lua/utils.lua index 8b221c7..66de1de 100644 --- a/nvim/lua/utils.lua +++ b/nvim/lua/utils.lua @@ -1,5 +1,8 @@ local M = {} +M.colorsync_theme = nil +M.ayu_colors = nil + function M.set_keymap_list(keymap_list, mode) mode = mode or "n" M.foreach(keymap_list, function(mapping)