X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/cc0c154184a778c60a0a6741f8e01483146569dc..HEAD:/nvim/lua/plugins/ui.lua?ds=sidebyside diff --git a/nvim/lua/plugins/ui.lua b/nvim/lua/plugins/ui.lua index fc905d7..56dcba9 100644 --- a/nvim/lua/plugins/ui.lua +++ b/nvim/lua/plugins/ui.lua @@ -1,9 +1,96 @@ +local M = {} + +---@param component any -- actually a lualine.component +---@param text string +---@param hl_group? string +---@return string +function M.format(component, text, hl_group) + text = text:gsub("%%", "%%%%") + if not hl_group or hl_group == "" then + return text + end + --- hl_cache is added here, not modified + ---@type table + component.hl_cache = component.hl_cache or {} + local lualine_hl_group = component.hl_cache[hl_group] + if not lualine_hl_group then + local utils = require("lualine.utils.utils") + ---@type string[] + local gui = vim.tbl_filter(function(x) return x end, { + utils.extract_highlight_colors(hl_group, "bold") and "bold", + utils.extract_highlight_colors(hl_group, "italic") and "italic", + }) + + lualine_hl_group = component:create_hl({ + fg = utils.extract_highlight_colors(hl_group, "fg"), + gui = #gui > 0 and table.concat(gui, ",") or nil, + }, "LV_" .. hl_group) --[[@as string]] + component.hl_cache[hl_group] = lualine_hl_group + end + return component:format_hl(lualine_hl_group) .. text .. component:get_default_hl() +end + +function M.pretty_path() + return function(self) + local opts = { + directory_hl = "", + filename_hl = "Bold", + length = 3, + modified_hl = "MatchParen", -- hl group when file is modified + modified_sign = "", + readonly_icon = " 󰌾 ", + } + + local path = vim.fn.expand("%:p") --[[@as string]] + + if path == "" then + return "" + end + + path = require("lazy.core.util").norm(path) + local cwd = vim.uv.cwd() + + if path:find(cwd, 1, true) == 1 then + path = path:sub(#cwd + 2) + end + + local sep = package.config:sub(1, 1) + local parts = vim.split(path, "[\\/]") + + if opts.length == 0 then + parts = parts + elseif #parts > opts.length then + parts = { parts[1], "…", unpack(parts, #parts - opts.length + 2, #parts) } + end + + if vim.bo.modified then + parts[#parts] = parts[#parts] .. opts.modified_sign + parts[#parts] = M.format(self, parts[#parts], opts.modified_hl) + else + parts[#parts] = M.format(self, parts[#parts], opts.filename_hl) + end + + local dir = "" + if #parts > 1 then + dir = table.concat({ unpack(parts, 1, #parts - 1) }, sep) + dir = M.format(self, dir .. sep, opts.directory_hl) + end + + local readonly = "" + if vim.bo.readonly then + readonly = M.format(self, opts.readonly_icon, opts.modified_hl) + end + return dir .. parts[#parts] .. readonly + end +end + ---@type LazySpec return { { 'echasnovski/mini.clue', -- NOTE: this caused some issue with unterminated mappings, i.e. gc when there -- is also gcc. It would simply terminate early and not allow for next mapping. version = '*', + lazy = true, -- NOTE: load this explicitely when needed, it blocks querying for key definitons via :Verbose map opts = { triggers = { { mode = 'n', keys = '' }, @@ -50,7 +137,7 @@ return { diagnostics = "nvim_lsp", always_show_bufferline = false, diagnostics_indicator = function(_, _, diag) - local icons = LazyVim.config.icons.diagnostics + local icons = rmz.ui.icons.diagnostics local ret = (diag.error and icons.Error .. diag.error .. " " or "") .. (diag.warning and icons.Warn .. diag.warning or "") return vim.trim(ret) @@ -65,7 +152,7 @@ return { }, ---@param opts bufferline.IconFetcherOpts get_element_icon = function(opts) - return LazyVim.config.icons.ft[opts.filetype] + return rmz.ui.icons.ft[opts.filetype] end, }, }, @@ -95,7 +182,7 @@ return { local lualine_require = require("lualine_require") lualine_require.require = require - local icons = LazyVim.config.icons + local icons = rmz.ui.icons vim.o.laststatus = vim.g.lualine_laststatus @@ -110,7 +197,6 @@ return { lualine_b = { "branch" }, lualine_c = { - LazyVim.lualine.root_dir(), { "diagnostics", symbols = { @@ -121,7 +207,7 @@ return { }, }, { "filetype", icon_only = true, separator = "", padding = { left = 1, right = 0 } }, - { LazyVim.lualine.pretty_path() }, + { M.pretty_path() }, }, lualine_x = { Snacks.profiler.status(), @@ -166,6 +252,12 @@ return { end, }, }, + inactive_sections = { + lualine_c = { + { "filetype", icon_only = true, separator = "", padding = { left = 1, right = 0 } }, + { M.pretty_path() }, + }, + }, extensions = { "neo-tree", "lazy", "fzf" }, } @@ -226,7 +318,7 @@ return { { "echasnovski/mini.indentscope", enabled = false, -- replaced by snacks.indent version = false, -- wait till new 0.7.0 release to put it back on semver - event = "LazyFile", + event = { "BufReadPost", "BufNewFile", "BufWritePre" }, opts = function (_, opts) return { draw = { @@ -239,7 +331,7 @@ return { lazy = true, init = function() vim.g.navic_silence = true - LazyVim.lsp.on_attach(function(client, buffer) + rmz.lsp.on_attach(function(client, buffer) if client.supports_method("textDocument/documentSymbol") then require("nvim-navic").attach(client, buffer) end @@ -250,7 +342,7 @@ return { separator = " ", highlight = true, depth_limit = 5, - icons = LazyVim.config.icons.kinds, + icons = rmz.ui.icons.kinds, lazy_update_context = true, } end,