Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add winbar support #689

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lua/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,35 @@ local function set_statusline()
end
end

--- Sets &winbar option to lualine
local function set_winbar()
if next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil then
vim.go.winbar = "%{%v:lua.require'lualine'.winbar()%}"
end
end

-- lualine.winbar function
--- Draw correct winbar for current window
---@param focused boolean : force the value of is_focused . useful for debugging
---@return string winbar string
local function winbar_dispatch(focused)
local retval
local current_ft = vim.bo.filetype
local is_focused = focused ~= nil and focused or modules.utils.is_focused()
for _, ft in pairs(config.options.disabled_filetypes) do
-- disable on specific filetypes
if ft == current_ft then
return ''
end
end
if is_focused then
retval = statusline(config.winbar, is_focused)
else
retval = statusline(config.inactive_winbar, is_focused)
end
return retval
end

-- lualine.statusline function
--- Draw correct statusline for current window
---@param focused boolean : force the value of is_focused . useful for debugging
Expand Down Expand Up @@ -331,6 +360,7 @@ local function setup(user_config)
-- load components & extensions
modules.loader.load_all(config)
set_statusline()
set_winbar()
set_tabline()
if package.loaded['lualine.utils.notices'] then
modules.utils_notices.notice_message_startup()
Expand All @@ -340,6 +370,7 @@ end
return {
setup = setup,
statusline = status_dispatch,
winbar = winbar_dispatch,
tabline = tabline,
get_config = modules.config_module.get_config,
}
4 changes: 4 additions & 0 deletions lua/lualine/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ local config = {
lualine_y = {},
lualine_z = {},
},
winbar = {},
inactive_winbar = {},
tabline = {},
extensions = {},
}
Expand Down Expand Up @@ -76,6 +78,8 @@ local function apply_configuration(config_table)
parse_sections('options')
parse_sections('sections')
parse_sections('inactive_sections')
parse_sections('winbar')
parse_sections('inactive_winbar')
parse_sections('tabline')
if config_table.extensions then
config.extensions = utils.deepcopy(config_table.extensions)
Expand Down
2 changes: 2 additions & 0 deletions lua/lualine/utils/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ local function load_components(config)
load_sections(config.sections, config.options)
load_sections(config.inactive_sections, config.options)
load_sections(config.tabline, config.options)
load_sections(config.winbar, config.options)
load_sections(config.inactive_winbar, config.options)
end

---loads all the extensions
Expand Down
2 changes: 2 additions & 0 deletions tests/spec/lualine_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe('Lualine', function()
lualine_y = {},
lualine_z = {},
},
winbar = {},
inactive_winbar = {},
tabline = {},
extensions = {},
}
Expand Down