From a051d107da7a2a889479316d0205150af79de61f Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Tue, 30 Jul 2024 13:41:14 -0400 Subject: [PATCH] feat(nvim/lualine): add command and mode --- pkgs/nvim/config/helpers.lua | 26 +++++++++++++++++++++++++ pkgs/nvim/config/sets.nix | 9 ++++++++- pkgs/nvim/config/statusline/lualine.nix | 25 ++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 pkgs/nvim/config/helpers.lua diff --git a/pkgs/nvim/config/helpers.lua b/pkgs/nvim/config/helpers.lua new file mode 100644 index 0000000..39141ca --- /dev/null +++ b/pkgs/nvim/config/helpers.lua @@ -0,0 +1,26 @@ +if MVim then return end -- avoid loading twice the same module +MVim = {} + +---@return {fg?:string}? +function MVim.fg(name) + local color = MVim.color(name) + return color and { fg = color } or nil +end + +---@param name string +---@param bg? boolean +---@return string? +function MVim.color(name, bg) + ---@type {fg?:number, bg?:number}? + local hl = vim.api.nvim_get_hl(0, { name = name, link = false }) + ---@type number? + local color = nil + if hl then + if bg then + color = hl.bg + else + color = hl.fg + end + end + return color and string.format("#%06x", color) or nil +end diff --git a/pkgs/nvim/config/sets.nix b/pkgs/nvim/config/sets.nix index 219298e..096b8a7 100644 --- a/pkgs/nvim/config/sets.nix +++ b/pkgs/nvim/config/sets.nix @@ -117,7 +117,6 @@ # We don't need to see things like INSERT anymore showmode = false; - showcmd = false; # Maximum number of items to show in the popup menu (0 means "use available screen space") pumheight = 0; @@ -128,6 +127,14 @@ laststatus = 3; # (https://neovim.io/doc/user/options.html#'laststatus') }; + extraFiles = { + "lua/helpers.lua".source = ./helpers.lua; + }; + + extraConfigLuaPre = '' + require "helpers" + ''; + extraConfigLua = '' local opt = vim.opt local g = vim.g diff --git a/pkgs/nvim/config/statusline/lualine.nix b/pkgs/nvim/config/statusline/lualine.nix index 6cb1293..6a6d434 100644 --- a/pkgs/nvim/config/statusline/lualine.nix +++ b/pkgs/nvim/config/statusline/lualine.nix @@ -17,7 +17,11 @@ left = ""; #  right = ""; #  }; - sections = { + sections = let + mkColor = color: { + __raw = ''function() return MVim.fg("${color}") end''; + }; + in { lualine_a = ["mode"]; lualine_b = ["branch"]; lualine_c = [ @@ -45,7 +49,24 @@ "filename" ]; - lualine_x = []; + lualine_x = [ + # Command + { + name.__raw = ''function() return require("noice").api.status.command.get() end''; + color = mkColor "Statement"; + extraConfig = { + cond.__raw = ''function() return package.loaded["noice"] and require("noice").api.status.command.has() end''; + }; + } + # Mode + { + name.__raw = ''function() return require("noice").api.status.mode.get() end''; + color = mkColor "Constant"; + extraConfig = { + cond.__raw = ''function() return package.loaded["noice"] and require("noice").api.status.mode.has() end''; + }; + } + ]; lualine_y = [ { name = "progress";