feat(nvim/lualine): add command and mode

This commit is contained in:
Michael Thomas 2024-07-30 13:41:14 -04:00
parent e7c5986b79
commit a051d107da
3 changed files with 57 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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";