feat(lualine): add custom setup options

This commit is contained in:
Ching Pei Yang 2024-01-03 00:55:15 +01:00
parent 4001943a7b
commit 376c8bafd0
2 changed files with 77 additions and 60 deletions

View file

@ -3,75 +3,70 @@
lib,
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.trivial) boolToString;
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) luaTable listToLuaTable;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.statusline.lualine;
breadcrumbsCfg = config.vim.ui.breadcrumbs;
rawLua = code: {"__raw" = code;};
in {
config = (mkIf cfg.enable) {
config = mkMerge [
# TODO: move into nvim-tree file
(mkIf (config.vim.filetree.nvimTree.enable) {
vim.statusline.lualine.setupOpts = {
extensions = ["nvim-tree"];
};
})
(mkIf (breadcrumbsCfg.enable && breadcrumbsCfg.source == "nvim-navic") {
vim.statusline.lualine.setupOpts = {
# TODO: rewrite in new syntax
winbar.lualine_c = [
"navic"
(rawLua "draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender}")
];
};
})
(mkIf cfg.enable {
vim.startPlugins = [
"lualine"
];
vim.luaConfigRC.lualine = entryAnywhere ''
local lualine = require('lualine')
lualine.setup {
options = {
icons_enabled = ${boolToString cfg.icons.enable},
theme = "${cfg.theme}",
component_separators = {"${cfg.componentSeparator.left}","${cfg.componentSeparator.right}"},
section_separators = {"${cfg.sectionSeparator.left}","${cfg.sectionSeparator.right}"},
disabled_filetypes = ${listToLuaTable cfg.disabledFiletypes},
always_divide_middle = ${boolToString cfg.alwaysDivideMiddle},
globalstatus = ${boolToString cfg.globalStatus},
ignore_focus = ${listToLuaTable cfg.ignoreFocus},
extensions = {${optionalString config.vim.filetree.nvimTree.enable "'nvim-tree'"}},
refresh = {
statusline = ${toString cfg.refresh.statusline},
tabline = ${toString cfg.refresh.tabline},
winbar = ${toString cfg.refresh.winbar},
},
},
-- active sections
sections = {
lualine_a = ${luaTable (cfg.activeSection.a ++ cfg.extraActiveSection.a)},
lualine_b = ${luaTable (cfg.activeSection.b ++ cfg.extraActiveSection.b)},
lualine_c = ${luaTable (cfg.activeSection.c ++ cfg.extraActiveSection.c)},
lualine_x = ${luaTable (cfg.activeSection.x ++ cfg.extraActiveSection.x)},
lualine_y = ${luaTable (cfg.activeSection.y ++ cfg.extraActiveSection.y)},
lualine_z = ${luaTable (cfg.activeSection.z ++ cfg.extraActiveSection.z)},
},
-- inactive sections
inactive_sections = {
lualine_a = ${luaTable (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a)},
lualine_b = ${luaTable (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b)},
lualine_c = ${luaTable (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c)},
lualine_x = ${luaTable (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x)},
lualine_y = ${luaTable (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y)},
lualine_z = ${luaTable (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z)},
},
-- tabline (currently unsupported)
tabline = {},
${optionalString (breadcrumbsCfg.enable && breadcrumbsCfg.source == "nvim-navic") ''
-- enable winbar if nvim-navic is enabled
winbar = {
lualine_c = {
{
"navic",
draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender}
}
}
},
''}
}
lualine.setup ${toLuaObject cfg.setupOpts}
'';
# this is for backwards-compatibility
vim.statusline.lualine.setupOpts = {
options = {
icons_enabled = cfg.icons.enable;
theme = cfg.theme;
component_separators = [cfg.componentSeparator.left cfg.componentSeparator.right];
section_separators = [cfg.sectionSeparator.left cfg.sectionSeparator.right];
globalstatus = cfg.globalStatus;
refresh = cfg.refresh;
};
sections = {
lualine_a = builtins.map rawLua (cfg.activeSection.a ++ cfg.extraActiveSection.a);
lualine_b = builtins.map rawLua (cfg.activeSection.b ++ cfg.extraActiveSection.b);
lualine_c = builtins.map rawLua (cfg.activeSection.c ++ cfg.extraActiveSection.c);
lualine_x = builtins.map rawLua (cfg.activeSection.x ++ cfg.extraActiveSection.x);
lualine_y = builtins.map rawLua (cfg.activeSection.y ++ cfg.extraActiveSection.y);
lualine_z = builtins.map rawLua (cfg.activeSection.z ++ cfg.extraActiveSection.z);
};
inactive_sections = {
lualine_a = builtins.map rawLua (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a);
lualine_b = builtins.map rawLua (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b);
lualine_c = builtins.map rawLua (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c);
lualine_x = builtins.map rawLua (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x);
lualine_y = builtins.map rawLua (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y);
lualine_z = builtins.map rawLua (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z);
};
# probably don't need this?
tabline = [];
};
})
];
}

View file

@ -7,14 +7,36 @@
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) int bool str listOf enum;
inherit (lib.lists) optional;
inherit (lib.nvim.types) mkPluginSetupOption;
supported_themes = import ./supported_themes.nix;
colorPuccin =
if config.vim.statusline.lualine.theme == "catppuccin"
then "#181825"
else "none";
tempDesc = "see plugin docs for more info";
in {
options.vim.statusline.lualine = {
setupOpts = mkPluginSetupOption "Lualine" {
options = {
disabled_filetypes = mkOption {
description = tempDesc;
type = listOf str;
default = ["alpha"];
};
always_divide_middle = mkOption {
description = tempDesc;
type = bool;
default = true;
};
ignore_focus = mkOption {
description = tempDesc;
type = listOf str;
default = ["NvimTree"];
};
};
};
enable = mkEnableOption "lualine statusline plugin";
icons = {