From 60b1d5dce9e0662f5c6ab140cf9dedd8bd50c7b2 Mon Sep 17 00:00:00 2001 From: Shadman <13149513+shadmansaleh@users.noreply.github.com> Date: Fri, 18 Mar 2022 06:59:01 +0600 Subject: [PATCH] feat: add support for global statusline (#613) --- README.md | 4 ++++ doc/lualine.txt | 4 ++++ lua/lualine.lua | 4 ++-- lua/lualine/config.lua | 11 +++++++++++ lua/tests/spec/lualine_spec.lua | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 157ae40..2814f72 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ require('lualine').setup { section_separators = { left = '', right = ''}, disabled_filetypes = {}, always_divide_middle = true, + globalstatus = false, }, sections = { lualine_a = {'mode'}, @@ -338,6 +339,9 @@ options = { always_divide_middle = true, -- When set to true, left sections i.e. 'a','b' and 'c' -- can't take over the entire statusline even -- if neither of 'x', 'y' or 'z' are present. + globalstatus = false, -- enable global statusline (have a single statusline + -- at bottom of neovim instead of one for every window). + -- This feature is only available in neovim 0.7 and higher. } ``` diff --git a/doc/lualine.txt b/doc/lualine.txt index 7468d1a..2774605 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -107,6 +107,7 @@ For more information, check out `:help lua-heredoc`. section_separators = { left = '', right = ''}, disabled_filetypes = {}, always_divide_middle = true, + globalstatus = false, }, sections = { lualine_a = {'mode'}, @@ -348,6 +349,9 @@ in component. always_divide_middle = true, -- When set to true, left sections i.e. 'a','b' and 'c' -- can't take over the entire statusline even -- if neither of 'x', 'y' or 'z' are present. + globalstatus = false, -- enable global statusline (have a single statusline + -- at bottom of neovim instead of one for every window). + -- This feature is only available in neovim 0.7 and higher. } < diff --git a/lua/lualine.lua b/lua/lualine.lua index 234b5d6..72bb6e9 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -269,7 +269,7 @@ local function set_statusline() if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then vim.cmd('autocmd lualine VimResized * redrawstatus') vim.go.statusline = "%{%v:lua.require'lualine'.statusline()%}" - vim.go.laststatus = 2 + vim.go.laststatus = config.options.globalstatus and 3 or 2 elseif vim.go.statusline == "%{%v:lua.require'lualine'.statusline()%}" then vim.go.statusline = nil vim.go.laststatus = 2 @@ -317,11 +317,11 @@ end --- sets &last_status tl 2 ---@param user_config table table local function setup(user_config) - config = modules.config_module.apply_configuration(user_config) if package.loaded['lualine.utils.notices'] then -- When notices module is not loaded there are no notices to clear. modules.utils_notices.clear_notices() end + config = modules.config_module.apply_configuration(user_config) vim.cmd([[augroup lualine | exe "autocmd!" | augroup END]]) setup_theme() -- load components & extensions diff --git a/lua/lualine/config.lua b/lua/lualine/config.lua index 92c28d9..3a5dc91 100644 --- a/lua/lualine/config.lua +++ b/lua/lualine/config.lua @@ -1,6 +1,10 @@ -- Copyright (c) 2020-2021 hoob3rt -- MIT license, see LICENSE for more details. +local require = require('lualine_require').require local utils = require('lualine.utils.utils') +local modules = require('lualine_require').lazy_require { + utils_notices = 'lualine.utils.notices', +} local config = { options = { @@ -10,6 +14,7 @@ local config = { section_separators = { left = '', right = '' }, disabled_filetypes = {}, always_divide_middle = true, + globalstatus = false, }, sections = { lualine_a = { 'mode' }, @@ -62,6 +67,12 @@ local function apply_configuration(config_table) config[section_group_name][section_name] = utils.deepcopy(section) end end + if config_table.options and config_table.options.globalstatus and vim.fn.has('nvim-0.7') == 0 then + modules.utils_notices.add_notice( + '### Options.globalstatus\nSorry `globalstatus` option can only be used in neovim 0.7 or higher.\n' + ) + config_table.options.globalstatus = false + end parse_sections('options') parse_sections('sections') parse_sections('inactive_sections') diff --git a/lua/tests/spec/lualine_spec.lua b/lua/tests/spec/lualine_spec.lua index a3067aa..82661c4 100644 --- a/lua/tests/spec/lualine_spec.lua +++ b/lua/tests/spec/lualine_spec.lua @@ -17,6 +17,7 @@ describe('Lualine', function() section_separators = { left = '', right = '' }, disabled_filetypes = {}, always_divide_middle = true, + globalstatus = false, }, sections = { lualine_a = { 'mode' },