From a99714dd328122a75fad75c53f3cb04677e6476e Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Thu, 30 Nov 2023 04:14:47 +0100 Subject: [PATCH] feat(lualine): customizable setup options --- modules/statusline/lualine/config.nix | 105 ++++++++++++------------- modules/statusline/lualine/lualine.nix | 24 ++++++ 2 files changed, 76 insertions(+), 53 deletions(-) diff --git a/modules/statusline/lualine/config.nix b/modules/statusline/lualine/config.nix index 986db00ca..59bfeee38 100644 --- a/modules/statusline/lualine/config.nix +++ b/modules/statusline/lualine/config.nix @@ -7,61 +7,60 @@ breadcrumbsCfg = config.vim.ui.breadcrumbs; inherit (lib) mkIf nvim boolToString optionalString; in { - config = (mkIf cfg.enable) { - vim.startPlugins = [ - "lualine" - ]; + config = mkMerge [ + (mkIf config.vim.ui.breadcrumbs.source + == "nvim-navic" { + vim.statusline.lualine.pluginOpts = { + # TODO: convert to new syntax + winbar.lualine_c = [ + "navic" + { + _type = "rawLua"; + lua = "draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender}"; + } + ]; + }; + }) + (mkIf cfg.enable { + vim.startPlugins = [ + "lualine" + ]; - vim.luaConfigRC.lualine = nvim.dag.entryAnywhere '' - local lualine = require('lualine') - lualine.setup { + vim.luaConfigRC.lualine = nvim.dag.entryAnywhere '' + local lualine = require('lualine') + lualine.setup ${lib.nvim.lua.expToLua cfg.pluginOpts} + ''; + + # this is for backwards-compatibility + vim.statusline.lualine.pluginOpts = { 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 = { 'alpha' }, - always_divide_middle = true, - globalstatus = ${boolToString cfg.globalStatus}, - ignore_focus = {'NvimTree'}, - 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 + 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 = ${nvim.lua.luaTable (cfg.activeSection.a ++ cfg.extraActiveSection.a)}, - lualine_b = ${nvim.lua.luaTable (cfg.activeSection.b ++ cfg.extraActiveSection.b)}, - lualine_c = ${nvim.lua.luaTable (cfg.activeSection.c ++ cfg.extraActiveSection.c)}, - lualine_x = ${nvim.lua.luaTable (cfg.activeSection.x ++ cfg.extraActiveSection.x)}, - lualine_y = ${nvim.lua.luaTable (cfg.activeSection.y ++ cfg.extraActiveSection.y)}, - lualine_z = ${nvim.lua.luaTable (cfg.activeSection.z ++ cfg.extraActiveSection.z)}, - }, - -- + lualine_a = cfg.activeSection.a ++ cfg.extraActiveSection.a; + lualine_b = cfg.activeSection.b ++ cfg.extraActiveSection.b; + lualine_c = cfg.activeSection.c ++ cfg.extraActiveSection.c; + lualine_x = cfg.activeSection.x ++ cfg.extraActiveSection.x; + lualine_y = cfg.activeSection.y ++ cfg.extraActiveSection.y; + lualine_z = cfg.activeSection.z ++ cfg.extraActiveSection.z; + }; inactive_sections = { - lualine_a = ${nvim.lua.luaTable (cfg.inactiveSection.a ++ cfg.extraInactiveSection.a)}, - lualine_b = ${nvim.lua.luaTable (cfg.inactiveSection.b ++ cfg.extraInactiveSection.b)}, - lualine_c = ${nvim.lua.luaTable (cfg.inactiveSection.c ++ cfg.extraInactiveSection.c)}, - lualine_x = ${nvim.lua.luaTable (cfg.inactiveSection.x ++ cfg.extraInactiveSection.x)}, - lualine_y = ${nvim.lua.luaTable (cfg.inactiveSection.y ++ cfg.extraInactiveSection.y)}, - lualine_z = ${nvim.lua.luaTable (cfg.inactiveSection.z ++ cfg.extraInactiveSection.z)}, - }, - tabline = {}, - - ${optionalString (breadcrumbsCfg.enable && breadcrumbsCfg.source == "nvim-navic") '' - winbar = { - lualine_c = { - { - "navic", - draw_empty = ${boolToString config.vim.ui.breadcrumbs.alwaysRender} - } - } - }, - ''} - } - ''; - }; + lualine_a = cfg.inactiveSection.a ++ cfg.extraInactiveSection.a; + lualine_b = cfg.inactiveSection.b ++ cfg.extraInactiveSection.b; + lualine_c = cfg.inactiveSection.c ++ cfg.extraInactiveSection.c; + lualine_x = cfg.inactiveSection.x ++ cfg.extraInactiveSection.x; + lualine_y = cfg.inactiveSection.y ++ cfg.extraInactiveSection.y; + lualine_z = cfg.inactiveSection.z ++ cfg.extraInactiveSection.z; + }; + # probably don't need this? + tabline = []; + }; + }) + ]; } diff --git a/modules/statusline/lualine/lualine.nix b/modules/statusline/lualine/lualine.nix index f3c430649..2fca16fe9 100644 --- a/modules/statusline/lualine/lualine.nix +++ b/modules/statusline/lualine/lualine.nix @@ -10,8 +10,32 @@ if config.vim.statusline.lualine.theme == "catppuccin" then "#181825" else "none"; + tempDesc = "see plugin docs for more info"; in { options.vim.statusline.lualine = { + setupOpts = lib.nvim.types.mkPluginSetupOption "Lualine" { + disabled_filetypes = mkOption { + description = tempDesc; + type = with types; listOf str; + default = ["alpha"]; + }; + always_divide_middle = mkOption { + description = tempDesc; + type = types.bool; + default = true; + }; + ignore_focus = mkOption { + description = tempDesc; + type = with types; listOf str; + default = ["NvimTree"]; + }; + extensions = mkOption { + description = tempDesc; + type = with types; listOf str; + default = [optionalString config.vim.filetree.nvimTree.enable "'nvim-tree'"]; + }; + }; + enable = mkEnableOption "lualine statusline plugin"; icons = {