feat: add support for global statusline (#613)

This commit is contained in:
Shadman 2022-03-18 06:59:01 +06:00 committed by GitHub
parent 88a44ade81
commit 60b1d5dce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 2 deletions

View File

@ -123,6 +123,7 @@ require('lualine').setup {
section_separators = { left = '', right = ''}, section_separators = { left = '', right = ''},
disabled_filetypes = {}, disabled_filetypes = {},
always_divide_middle = true, always_divide_middle = true,
globalstatus = false,
}, },
sections = { sections = {
lualine_a = {'mode'}, lualine_a = {'mode'},
@ -338,6 +339,9 @@ options = {
always_divide_middle = true, -- When set to true, left sections i.e. 'a','b' and 'c' always_divide_middle = true, -- When set to true, left sections i.e. 'a','b' and 'c'
-- can't take over the entire statusline even -- can't take over the entire statusline even
-- if neither of 'x', 'y' or 'z' are present. -- 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.
} }
``` ```

View File

@ -107,6 +107,7 @@ For more information, check out `:help lua-heredoc`.
section_separators = { left = '', right = ''}, section_separators = { left = '', right = ''},
disabled_filetypes = {}, disabled_filetypes = {},
always_divide_middle = true, always_divide_middle = true,
globalstatus = false,
}, },
sections = { sections = {
lualine_a = {'mode'}, 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' always_divide_middle = true, -- When set to true, left sections i.e. 'a','b' and 'c'
-- can't take over the entire statusline even -- can't take over the entire statusline even
-- if neither of 'x', 'y' or 'z' are present. -- 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.
} }
< <

View File

@ -269,7 +269,7 @@ local function set_statusline()
if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then
vim.cmd('autocmd lualine VimResized * redrawstatus') vim.cmd('autocmd lualine VimResized * redrawstatus')
vim.go.statusline = "%{%v:lua.require'lualine'.statusline()%}" 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 elseif vim.go.statusline == "%{%v:lua.require'lualine'.statusline()%}" then
vim.go.statusline = nil vim.go.statusline = nil
vim.go.laststatus = 2 vim.go.laststatus = 2
@ -317,11 +317,11 @@ end
--- sets &last_status tl 2 --- sets &last_status tl 2
---@param user_config table table ---@param user_config table table
local function setup(user_config) local function setup(user_config)
config = modules.config_module.apply_configuration(user_config)
if package.loaded['lualine.utils.notices'] then if package.loaded['lualine.utils.notices'] then
-- When notices module is not loaded there are no notices to clear. -- When notices module is not loaded there are no notices to clear.
modules.utils_notices.clear_notices() modules.utils_notices.clear_notices()
end end
config = modules.config_module.apply_configuration(user_config)
vim.cmd([[augroup lualine | exe "autocmd!" | augroup END]]) vim.cmd([[augroup lualine | exe "autocmd!" | augroup END]])
setup_theme() setup_theme()
-- load components & extensions -- load components & extensions

View File

@ -1,6 +1,10 @@
-- Copyright (c) 2020-2021 hoob3rt -- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
local require = require('lualine_require').require
local utils = require('lualine.utils.utils') local utils = require('lualine.utils.utils')
local modules = require('lualine_require').lazy_require {
utils_notices = 'lualine.utils.notices',
}
local config = { local config = {
options = { options = {
@ -10,6 +14,7 @@ local config = {
section_separators = { left = '', right = '' }, section_separators = { left = '', right = '' },
disabled_filetypes = {}, disabled_filetypes = {},
always_divide_middle = true, always_divide_middle = true,
globalstatus = false,
}, },
sections = { sections = {
lualine_a = { 'mode' }, lualine_a = { 'mode' },
@ -62,6 +67,12 @@ local function apply_configuration(config_table)
config[section_group_name][section_name] = utils.deepcopy(section) config[section_group_name][section_name] = utils.deepcopy(section)
end end
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('options')
parse_sections('sections') parse_sections('sections')
parse_sections('inactive_sections') parse_sections('inactive_sections')

View File

@ -17,6 +17,7 @@ describe('Lualine', function()
section_separators = { left = '', right = '' }, section_separators = { left = '', right = '' },
disabled_filetypes = {}, disabled_filetypes = {},
always_divide_middle = true, always_divide_middle = true,
globalstatus = false,
}, },
sections = { sections = {
lualine_a = { 'mode' }, lualine_a = { 'mode' },