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, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf mkMerge;
inherit (lib.trivial) boolToString; inherit (lib.trivial) boolToString;
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) luaTable listToLuaTable;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.statusline.lualine; cfg = config.vim.statusline.lualine;
breadcrumbsCfg = config.vim.ui.breadcrumbs; breadcrumbsCfg = config.vim.ui.breadcrumbs;
rawLua = code: {"__raw" = code;};
in { in {
config = (mkIf cfg.enable) { config = mkMerge [
vim.startPlugins = [ # TODO: move into nvim-tree file
"lualine" (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 '' vim.luaConfigRC.lualine = entryAnywhere ''
local lualine = require('lualine') local lualine = require('lualine')
lualine.setup { lualine.setup ${toLuaObject cfg.setupOpts}
'';
# this is for backwards-compatibility
vim.statusline.lualine.setupOpts = {
options = { options = {
icons_enabled = ${boolToString cfg.icons.enable}, icons_enabled = cfg.icons.enable;
theme = "${cfg.theme}", theme = cfg.theme;
component_separators = {"${cfg.componentSeparator.left}","${cfg.componentSeparator.right}"}, component_separators = [cfg.componentSeparator.left cfg.componentSeparator.right];
section_separators = {"${cfg.sectionSeparator.left}","${cfg.sectionSeparator.right}"}, section_separators = [cfg.sectionSeparator.left cfg.sectionSeparator.right];
disabled_filetypes = ${listToLuaTable cfg.disabledFiletypes}, globalstatus = cfg.globalStatus;
always_divide_middle = ${boolToString cfg.alwaysDivideMiddle}, refresh = cfg.refresh;
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 = { sections = {
lualine_a = ${luaTable (cfg.activeSection.a ++ cfg.extraActiveSection.a)}, lualine_a = builtins.map rawLua (cfg.activeSection.a ++ cfg.extraActiveSection.a);
lualine_b = ${luaTable (cfg.activeSection.b ++ cfg.extraActiveSection.b)}, lualine_b = builtins.map rawLua (cfg.activeSection.b ++ cfg.extraActiveSection.b);
lualine_c = ${luaTable (cfg.activeSection.c ++ cfg.extraActiveSection.c)}, lualine_c = builtins.map rawLua (cfg.activeSection.c ++ cfg.extraActiveSection.c);
lualine_x = ${luaTable (cfg.activeSection.x ++ cfg.extraActiveSection.x)}, lualine_x = builtins.map rawLua (cfg.activeSection.x ++ cfg.extraActiveSection.x);
lualine_y = ${luaTable (cfg.activeSection.y ++ cfg.extraActiveSection.y)}, lualine_y = builtins.map rawLua (cfg.activeSection.y ++ cfg.extraActiveSection.y);
lualine_z = ${luaTable (cfg.activeSection.z ++ cfg.extraActiveSection.z)}, lualine_z = builtins.map rawLua (cfg.activeSection.z ++ cfg.extraActiveSection.z);
}, };
-- inactive sections
inactive_sections = { inactive_sections = {
lualine_a = ${luaTable (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a)}, lualine_a = builtins.map rawLua (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a);
lualine_b = ${luaTable (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b)}, lualine_b = builtins.map rawLua (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b);
lualine_c = ${luaTable (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c)}, lualine_c = builtins.map rawLua (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c);
lualine_x = ${luaTable (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x)}, lualine_x = builtins.map rawLua (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x);
lualine_y = ${luaTable (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y)}, lualine_y = builtins.map rawLua (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y);
lualine_z = ${luaTable (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z)}, lualine_z = builtins.map rawLua (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z);
}, };
# probably don't need this?
-- tabline (currently unsupported) tabline = [];
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}
}
}
},
''}
}
'';
};
} }

View file

@ -7,14 +7,36 @@
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) int bool str listOf enum; inherit (lib.types) int bool str listOf enum;
inherit (lib.lists) optional; inherit (lib.lists) optional;
inherit (lib.nvim.types) mkPluginSetupOption;
supported_themes = import ./supported_themes.nix; supported_themes = import ./supported_themes.nix;
colorPuccin = colorPuccin =
if config.vim.statusline.lualine.theme == "catppuccin" if config.vim.statusline.lualine.theme == "catppuccin"
then "#181825" then "#181825"
else "none"; else "none";
tempDesc = "see plugin docs for more info";
in { in {
options.vim.statusline.lualine = { 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"; enable = mkEnableOption "lualine statusline plugin";
icons = { icons = {