2021-02-13 00:03:57 +00:00
|
|
|
-- Copyright (c) 2020-2021 hoob3rt
|
|
|
|
-- MIT license, see LICENSE for more details.
|
2022-07-22 13:29:55 +00:00
|
|
|
local M = {}
|
|
|
|
|
2022-01-02 11:38:39 +00:00
|
|
|
local lualine_require = require('lualine_require')
|
2022-02-01 08:04:03 +00:00
|
|
|
local modules = lualine_require.lazy_require {
|
2021-08-16 17:19:56 +00:00
|
|
|
highlight = 'lualine.highlight',
|
|
|
|
loader = 'lualine.utils.loader',
|
|
|
|
utils_section = 'lualine.utils.section',
|
|
|
|
utils = 'lualine.utils.utils',
|
|
|
|
utils_notices = 'lualine.utils.notices',
|
2021-09-03 09:59:00 +00:00
|
|
|
config_module = 'lualine.config',
|
2022-07-22 13:30:37 +00:00
|
|
|
nvim_opts = 'lualine.utils.nvim_opts',
|
2022-02-01 08:04:03 +00:00
|
|
|
}
|
2022-01-09 16:30:19 +00:00
|
|
|
local config -- Stores currently applied config
|
2022-07-22 13:29:55 +00:00
|
|
|
local timers = {
|
|
|
|
stl_timer = vim.loop.new_timer(),
|
|
|
|
tal_timer = vim.loop.new_timer(),
|
|
|
|
wb_timer = vim.loop.new_timer(),
|
|
|
|
}
|
2020-12-30 14:48:51 +00:00
|
|
|
|
2022-07-22 13:29:55 +00:00
|
|
|
-- The events on which lualine redraws itself
|
2022-07-23 06:50:25 +00:00
|
|
|
local default_refresh_events = 'WinEnter,BufEnter,SessionLoadPost,FileChangedShellPost,VimResized,Filetype'
|
2022-07-22 13:29:55 +00:00
|
|
|
if vim.fn.has('nvim-0.7') == 1 then -- utilize ModeChanged event introduced in 0.7
|
2022-07-22 13:30:37 +00:00
|
|
|
default_refresh_events = default_refresh_events .. ',ModeChanged'
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
2021-08-26 18:09:02 +00:00
|
|
|
-- Helper for apply_transitional_separators()
|
2022-05-30 14:25:05 +00:00
|
|
|
--- finds first applied highlight group after str_checked in status
|
|
|
|
---@param status string : unprocessed statusline string
|
2021-10-12 14:04:47 +00:00
|
|
|
---@param str_checked number : position of how far status has been checked
|
|
|
|
---@return string|nil the hl group name or nil
|
2021-08-30 03:37:50 +00:00
|
|
|
local function find_next_hl(status, str_checked)
|
2021-08-26 18:09:02 +00:00
|
|
|
-- Gets the next valid hl group from str_checked
|
|
|
|
local hl_pos_start, hl_pos_end = status:find('%%#.-#', str_checked)
|
|
|
|
while true do
|
2021-09-03 18:28:20 +00:00
|
|
|
if not hl_pos_start then
|
|
|
|
return nil
|
|
|
|
end
|
2021-08-26 18:09:02 +00:00
|
|
|
-- When there are more that one hl group next to one another like
|
|
|
|
-- %#HL1#%#HL2#%#HL3# we need to return HL3. This makes that happen.
|
|
|
|
local next_start, next_end = status:find('^%%#.-#', hl_pos_end + 1)
|
2021-09-03 18:28:20 +00:00
|
|
|
if next_start == nil then
|
|
|
|
break
|
|
|
|
end
|
2021-08-26 18:09:02 +00:00
|
|
|
hl_pos_start, hl_pos_end = next_start, next_end
|
|
|
|
end
|
2021-08-30 03:37:50 +00:00
|
|
|
return status:sub(hl_pos_start + 2, hl_pos_end - 1)
|
2021-08-26 18:09:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Helper for apply_transitional_separators()
|
2021-10-12 14:04:47 +00:00
|
|
|
--- applies transitional separator highlight + transitional separator
|
2022-05-30 14:25:05 +00:00
|
|
|
---@param status string : unprocessed statusline string
|
2021-10-12 14:04:47 +00:00
|
|
|
---@param str_checked number : position of how far status has been checked
|
|
|
|
---@param last_hl string : last applied hl group name before str_checked
|
|
|
|
---@param reverse boolean : reverse the hl group ( true for right separators )
|
2022-05-30 14:25:05 +00:00
|
|
|
---@return string|nil concatenate separator highlight and transitional separator
|
2022-04-01 03:02:43 +00:00
|
|
|
local function fill_section_separator(status, is_focused, str_checked, last_hl, sep, reverse)
|
2021-08-26 18:09:02 +00:00
|
|
|
-- Inserts transitional separator along with transitional highlight
|
2021-08-30 03:37:50 +00:00
|
|
|
local next_hl = find_next_hl(status, str_checked)
|
2021-09-03 18:28:20 +00:00
|
|
|
if last_hl == nil then
|
2022-04-01 03:02:43 +00:00
|
|
|
last_hl = modules.highlight.get_stl_default_hl(is_focused)
|
2021-09-03 18:28:20 +00:00
|
|
|
end
|
|
|
|
if next_hl == nil then
|
2022-04-01 03:02:43 +00:00
|
|
|
next_hl = modules.highlight.get_stl_default_hl(is_focused)
|
2021-09-03 18:28:20 +00:00
|
|
|
end
|
|
|
|
if #next_hl == 0 or #last_hl == 0 then
|
|
|
|
return
|
|
|
|
end
|
2021-08-26 18:09:02 +00:00
|
|
|
local transitional_highlight = reverse -- lua ternary assignment x ? y : z
|
2021-09-03 18:28:20 +00:00
|
|
|
and modules.highlight.get_transitional_highlights(last_hl, next_hl)
|
|
|
|
or modules.highlight.get_transitional_highlights(next_hl, last_hl)
|
2021-08-26 18:09:02 +00:00
|
|
|
if transitional_highlight then
|
|
|
|
return transitional_highlight .. sep
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
--- processes statusline string
|
|
|
|
--- replaces %s/S{sep} with proper left/right separator highlight + sep
|
2022-05-30 14:25:05 +00:00
|
|
|
---@param status string : unprocessed statusline string
|
2021-10-12 14:04:47 +00:00
|
|
|
---@return string : processed statusline string
|
2022-04-01 03:02:43 +00:00
|
|
|
local function apply_transitional_separators(status, is_focused)
|
2022-05-30 14:25:05 +00:00
|
|
|
local status_applied = {} -- Collects all the pieces for concatenation
|
|
|
|
local last_hl -- Stores last highlight group that we found
|
|
|
|
local last_hl_reseted = false -- Whether last_hl is nil after reset
|
2021-09-08 14:53:23 +00:00
|
|
|
-- it after %=
|
2021-09-03 18:28:20 +00:00
|
|
|
local copied_pos = 1 -- Tracks how much we've copied over to status_applied
|
2021-08-25 11:43:12 +00:00
|
|
|
local str_checked = 1 -- Tracks where the searcher head is at
|
2021-05-07 00:54:49 +00:00
|
|
|
|
2021-08-25 11:43:12 +00:00
|
|
|
-- Process entire status replace the %s{sep} & %S{sep} placeholders
|
|
|
|
-- with proper transitional separator.
|
|
|
|
while str_checked ~= nil do
|
|
|
|
str_checked = status:find('%%', str_checked)
|
2021-09-03 18:28:20 +00:00
|
|
|
if str_checked == nil then
|
|
|
|
break
|
|
|
|
end
|
2021-08-25 11:43:12 +00:00
|
|
|
table.insert(status_applied, status:sub(copied_pos, str_checked - 1))
|
2021-09-03 18:28:20 +00:00
|
|
|
-- -1 so we don't copy '%'
|
2021-08-25 11:43:12 +00:00
|
|
|
copied_pos = str_checked
|
2021-09-03 18:28:20 +00:00
|
|
|
local next_char = modules.utils.charAt(status, str_checked + 1)
|
2021-08-25 11:43:12 +00:00
|
|
|
if next_char == '#' then
|
|
|
|
-- %#hl_name# highlights
|
2021-08-30 03:37:50 +00:00
|
|
|
last_hl = status:match('^%%#(.-)#', str_checked)
|
|
|
|
str_checked = str_checked + #last_hl + 3
|
2021-08-25 11:43:12 +00:00
|
|
|
elseif next_char == 's' then
|
|
|
|
-- %s{sep} is marker for left separator and
|
|
|
|
local sep = status:match('^%%s{(.-)}', str_checked)
|
|
|
|
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
|
2021-09-08 14:53:23 +00:00
|
|
|
if not (last_hl == nil and last_hl_reseted) then
|
2022-04-01 03:02:43 +00:00
|
|
|
local trans_sep = fill_section_separator(status, is_focused, str_checked, last_hl, sep, false)
|
2021-09-08 14:53:23 +00:00
|
|
|
if trans_sep then
|
|
|
|
table.insert(status_applied, trans_sep)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if last_hl_reseted then
|
|
|
|
last_hl_reseted = false
|
2021-09-03 18:28:20 +00:00
|
|
|
end
|
2021-08-25 11:43:12 +00:00
|
|
|
copied_pos = str_checked
|
|
|
|
elseif next_char == 'S' then
|
|
|
|
-- %S{sep} is marker for right separator and
|
|
|
|
local sep = status:match('^%%S{(.-)}', str_checked)
|
|
|
|
str_checked = str_checked + #sep + 4 -- 4 = len(%{})
|
2021-08-30 03:41:26 +00:00
|
|
|
if status:find('^%%s', str_checked) or status:find('^%%<%%s', str_checked) then
|
2021-08-26 11:26:13 +00:00
|
|
|
-- When transitional right_sep and left_sep are right next to each other
|
|
|
|
-- and in this exact order skip the left sep as we can't draw both.
|
|
|
|
str_checked = status:find('}', str_checked) + 1
|
|
|
|
end
|
2022-04-01 03:02:43 +00:00
|
|
|
local trans_sep = fill_section_separator(status, is_focused, str_checked, last_hl, sep, true)
|
2021-09-03 18:28:20 +00:00
|
|
|
if trans_sep then
|
|
|
|
table.insert(status_applied, trans_sep)
|
|
|
|
end
|
2021-08-25 11:43:12 +00:00
|
|
|
copied_pos = str_checked
|
|
|
|
elseif next_char == '%' then
|
|
|
|
str_checked = str_checked + 2 -- Skip the following % too
|
2022-01-02 11:38:39 +00:00
|
|
|
elseif next_char == '=' and last_hl and (last_hl:find('^lualine_a') or last_hl:find('^lualine_b')) then
|
2021-08-26 14:29:25 +00:00
|
|
|
-- TODO: Fix this properly
|
2022-05-30 14:25:05 +00:00
|
|
|
-- This check for lualine_a and lualine_b is dumb. It doesn't guarantee
|
|
|
|
-- c or x section isn't present. Worst case scenario after this patch
|
2021-08-26 14:29:25 +00:00
|
|
|
-- we have another visual bug that occurs less frequently.
|
2022-05-30 14:25:05 +00:00
|
|
|
-- Annoying Edge Cases
|
2021-08-30 03:37:50 +00:00
|
|
|
last_hl = nil
|
2021-09-08 14:53:23 +00:00
|
|
|
last_hl_reseted = true
|
2021-08-25 12:35:41 +00:00
|
|
|
str_checked = str_checked + 1 -- Skip the following % too
|
2021-05-07 15:39:28 +00:00
|
|
|
else
|
2021-08-25 11:43:12 +00:00
|
|
|
str_checked = str_checked + 1 -- Push it forward to avoid inf loop
|
2021-05-07 15:39:28 +00:00
|
|
|
end
|
|
|
|
end
|
2021-08-25 11:43:12 +00:00
|
|
|
table.insert(status_applied, status:sub(copied_pos)) -- Final chunk
|
|
|
|
return table.concat(status_applied)
|
2021-05-07 15:39:28 +00:00
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
--- creates the statusline string
|
|
|
|
---@param sections table : section config where components are replaced with
|
|
|
|
--- component objects
|
2022-05-30 14:25:05 +00:00
|
|
|
---@param is_focused boolean : whether being evaluated for focused window or not
|
2021-10-12 14:04:47 +00:00
|
|
|
---@return string statusline string
|
2022-07-22 13:29:55 +00:00
|
|
|
local statusline = modules.utils.retry_call_wrap(function(sections, is_focused, is_winbar)
|
2021-08-25 11:43:12 +00:00
|
|
|
-- The sequence sections should maintain [SECTION_SEQUENCE]
|
2021-09-03 18:28:20 +00:00
|
|
|
local section_sequence = { 'a', 'b', 'c', 'x', 'y', 'z' }
|
2021-08-25 11:43:12 +00:00
|
|
|
local status = {}
|
2021-10-07 22:18:14 +00:00
|
|
|
local applied_midsection_divider = false
|
2021-08-27 19:06:19 +00:00
|
|
|
local applied_trunc = false
|
2021-05-07 15:39:28 +00:00
|
|
|
for _, section_name in ipairs(section_sequence) do
|
|
|
|
if sections['lualine_' .. section_name] then
|
|
|
|
-- insert highlight+components of this section to status_builder
|
2022-07-22 13:39:52 +00:00
|
|
|
local section_data =
|
|
|
|
modules.utils_section.draw_section(sections['lualine_' .. section_name], section_name, is_focused)
|
2021-05-07 15:39:28 +00:00
|
|
|
if #section_data > 0 then
|
2021-10-07 22:18:14 +00:00
|
|
|
if not applied_midsection_divider and section_name > 'c' then
|
|
|
|
applied_midsection_divider = true
|
2022-03-02 13:37:08 +00:00
|
|
|
section_data = modules.highlight.format_highlight('c', is_focused) .. '%=' .. section_data
|
2021-08-25 11:43:12 +00:00
|
|
|
end
|
2021-08-27 19:06:19 +00:00
|
|
|
if not applied_trunc and section_name > 'b' then
|
|
|
|
applied_trunc = true
|
2021-09-03 18:28:20 +00:00
|
|
|
section_data = '%<' .. section_data
|
2021-08-27 19:06:19 +00:00
|
|
|
end
|
2021-08-25 11:43:12 +00:00
|
|
|
table.insert(status, section_data)
|
2021-05-07 15:39:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-07-22 13:29:55 +00:00
|
|
|
if applied_midsection_divider == false and config.options.always_divide_middle ~= false and not is_winbar then
|
2021-10-07 22:18:14 +00:00
|
|
|
-- When non of section x,y,z is present
|
2022-03-02 13:37:08 +00:00
|
|
|
table.insert(status, modules.highlight.format_highlight('c', is_focused) .. '%=')
|
2021-10-07 22:18:14 +00:00
|
|
|
end
|
2022-04-01 03:02:43 +00:00
|
|
|
return apply_transitional_separators(table.concat(status), is_focused)
|
2022-01-31 17:34:53 +00:00
|
|
|
end)
|
2020-12-30 14:48:51 +00:00
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
--- check if any extension matches the filetype and return proper sections
|
|
|
|
---@param current_ft string : filetype name of current file
|
2022-05-30 14:25:05 +00:00
|
|
|
---@param is_focused boolean : whether being evaluated for focused window or not
|
2021-10-12 14:04:47 +00:00
|
|
|
---@return table : (section_table) section config where components are replaced with
|
|
|
|
--- component objects
|
2022-05-30 14:25:05 +00:00
|
|
|
-- TODO: change this so it uses a hash table instead of iteration over list
|
2021-10-12 14:04:47 +00:00
|
|
|
-- to improve redraws. Add buftype / bufname for extensions
|
|
|
|
-- or some kind of cond ?
|
2022-07-22 13:29:55 +00:00
|
|
|
local function get_extension_sections(current_ft, is_focused, sec_name)
|
2021-03-17 00:02:13 +00:00
|
|
|
for _, extension in ipairs(config.extensions) do
|
2022-07-22 13:29:55 +00:00
|
|
|
if vim.tbl_contains(extension.filetypes, current_ft) then
|
|
|
|
return extension[(is_focused and '' or 'inactive_') .. sec_name]
|
2021-03-13 00:21:37 +00:00
|
|
|
end
|
|
|
|
end
|
2021-05-11 19:40:54 +00:00
|
|
|
return nil
|
2021-03-13 00:21:37 +00:00
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
---@return string statusline string for tabline
|
2021-09-03 18:28:20 +00:00
|
|
|
local function tabline()
|
2022-04-01 03:02:43 +00:00
|
|
|
return statusline(config.tabline, 3)
|
2021-09-03 18:28:20 +00:00
|
|
|
end
|
2021-03-06 15:03:00 +00:00
|
|
|
|
2021-08-14 06:02:30 +00:00
|
|
|
local function notify_theme_error(theme_name)
|
2021-09-03 18:28:20 +00:00
|
|
|
local message_template = theme_name ~= 'auto'
|
|
|
|
and [[
|
2021-08-14 06:02:30 +00:00
|
|
|
### options.theme
|
|
|
|
Theme `%s` not found, falling back to `auto`. Check if spelling is right.
|
2021-09-03 18:28:20 +00:00
|
|
|
]]
|
|
|
|
or [[
|
2021-08-14 06:02:30 +00:00
|
|
|
### options.theme
|
|
|
|
Theme `%s` failed, falling back to `gruvbox`.
|
|
|
|
This shouldn't happen.
|
2021-10-22 04:57:04 +00:00
|
|
|
Please report the issue at https://github.com/nvim-lualine/lualine.nvim/issues .
|
2021-08-14 06:02:30 +00:00
|
|
|
Also provide what colorscheme you're using.
|
|
|
|
]]
|
2021-08-16 17:19:56 +00:00
|
|
|
modules.utils_notices.add_notice(string.format(message_template, theme_name))
|
2021-08-14 06:02:30 +00:00
|
|
|
end
|
|
|
|
|
2022-05-30 14:25:05 +00:00
|
|
|
--- Sets up theme by defining hl groups and setting theme cache in 'highlight.lua'.
|
|
|
|
--- Uses 'options.theme' variable to apply the theme:
|
|
|
|
--- - If the value is a string, it'll load a theme of that name.
|
|
|
|
--- - If it's a table, it's directly used as the theme.
|
|
|
|
--- If loading the theme fails, this falls back to 'auto' theme.
|
|
|
|
--- If the 'auto' theme also fails, this falls back to 'gruvbox' theme.
|
|
|
|
--- Also sets up auto command to reload lualine on ColorScheme or background changes.
|
2021-03-06 15:03:00 +00:00
|
|
|
local function setup_theme()
|
2021-08-02 15:16:17 +00:00
|
|
|
local function get_theme_from_config()
|
|
|
|
local theme_name = config.options.theme
|
|
|
|
if type(theme_name) == 'string' then
|
2021-08-16 17:19:56 +00:00
|
|
|
local ok, theme = pcall(modules.loader.load_theme, theme_name)
|
2021-09-03 18:28:20 +00:00
|
|
|
if ok and theme then
|
|
|
|
return theme
|
|
|
|
end
|
2021-08-02 15:16:17 +00:00
|
|
|
elseif type(theme_name) == 'table' then
|
|
|
|
-- use the provided theme as-is
|
|
|
|
return config.options.theme
|
|
|
|
end
|
2021-08-14 06:02:30 +00:00
|
|
|
if theme_name ~= 'auto' then
|
|
|
|
notify_theme_error(theme_name)
|
2021-08-16 17:19:56 +00:00
|
|
|
local ok, theme = pcall(modules.loader.load_theme, 'auto')
|
2021-09-03 18:28:20 +00:00
|
|
|
if ok and theme then
|
|
|
|
return theme
|
|
|
|
end
|
2021-08-14 06:02:30 +00:00
|
|
|
end
|
2022-01-02 11:38:39 +00:00
|
|
|
notify_theme_error('auto')
|
|
|
|
return modules.loader.load_theme('gruvbox')
|
2021-08-02 15:16:17 +00:00
|
|
|
end
|
|
|
|
local theme = get_theme_from_config()
|
2021-08-16 17:19:56 +00:00
|
|
|
modules.highlight.create_highlight_groups(theme)
|
2022-01-02 11:38:39 +00:00
|
|
|
vim.cmd([[autocmd lualine ColorScheme * lua require'lualine'.setup()
|
|
|
|
autocmd lualine OptionSet background lua require'lualine'.setup()]])
|
2021-01-04 00:17:51 +00:00
|
|
|
end
|
|
|
|
|
2022-07-22 13:29:55 +00:00
|
|
|
---@alias StatusDispatchSecs
|
|
|
|
---| 'sections'
|
|
|
|
---| 'winbar'
|
|
|
|
--- generates lualine.statusline & lualine.winbar function
|
|
|
|
--- creates a closer that can draw sections of sec_name.
|
|
|
|
---@param sec_name StatusDispatchSecs
|
|
|
|
---@return function(focused:bool):string
|
|
|
|
local function status_dispatch(sec_name)
|
|
|
|
return function(focused)
|
|
|
|
local retval
|
|
|
|
local current_ft = vim.bo.filetype
|
|
|
|
local is_focused = focused ~= nil and focused or modules.utils.is_focused()
|
2022-07-22 13:30:37 +00:00
|
|
|
if
|
|
|
|
vim.tbl_contains(
|
|
|
|
config.options.disabled_filetypes[(sec_name == 'sections' and 'statusline' or sec_name)],
|
|
|
|
current_ft
|
|
|
|
)
|
|
|
|
then
|
2022-07-22 13:29:55 +00:00
|
|
|
-- disable on specific filetypes
|
|
|
|
return ''
|
|
|
|
end
|
|
|
|
local extension_sections = get_extension_sections(current_ft, is_focused, sec_name)
|
|
|
|
if extension_sections ~= nil then
|
|
|
|
retval = statusline(extension_sections, is_focused, sec_name == 'winbar')
|
|
|
|
else
|
2022-07-22 13:30:37 +00:00
|
|
|
retval = statusline(config[(is_focused and '' or 'inactive_') .. sec_name], is_focused, sec_name == 'winbar')
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
|
|
|
return retval
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
---@alias LualineRefreshOptsKind
|
|
|
|
---| 'all'
|
|
|
|
---| 'tabpage'
|
|
|
|
---| 'window'
|
|
|
|
---@alias LualineRefreshOptsPlace
|
|
|
|
---| 'statusline'
|
|
|
|
---| 'tabline'
|
|
|
|
---| 'winbar'
|
|
|
|
---@class LualineRefreshOpts
|
|
|
|
---@field kind LualineRefreshOptsKind
|
|
|
|
---@field place LualineRefreshOptsPlace[]
|
|
|
|
---@field trigger 'autocmd'|'timer'|'unknown'
|
|
|
|
--- Refresh contents of lualine
|
|
|
|
---@param opts LualineRefreshOpts
|
|
|
|
local function refresh(opts)
|
|
|
|
if opts == nil then
|
2022-07-22 13:30:37 +00:00
|
|
|
opts = { kind = 'tabpage', place = { 'statusline', 'winbar', 'tabline' }, trigger = 'unknown' }
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
|
|
|
|
2022-07-27 15:51:54 +00:00
|
|
|
-- updating statusline in autocommands context seems to trigger 100 different bugs
|
|
|
|
-- lets just defer it to a timer context and update there
|
|
|
|
-- workaround for https://github.com/neovim/neovim/issues/15300
|
2022-07-22 13:29:55 +00:00
|
|
|
-- workaround for https://github.com/neovim/neovim/issues/19464
|
2022-07-27 15:51:54 +00:00
|
|
|
-- workaround for https://github.com/nvim-lualine/lualine.nvim/issues/753
|
|
|
|
-- workaround for https://github.com/nvim-lualine/lualine.nvim/issues/751
|
|
|
|
-- workaround for https://github.com/nvim-lualine/lualine.nvim/issues/755
|
|
|
|
if opts.trigger == 'autocmd' then
|
|
|
|
opts.trigger = 'timer'
|
|
|
|
vim.defer_fn(function() M.refresh(opts) end, 50)
|
|
|
|
return
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local wins = {}
|
|
|
|
local old_actual_curwin = vim.g.actual_curwin
|
|
|
|
vim.g.actual_curwin = vim.api.nvim_get_current_win()
|
|
|
|
-- gather which windows needs update
|
|
|
|
if opts.kind == 'all' then
|
2022-07-22 13:30:37 +00:00
|
|
|
if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
|
|
|
|
wins = vim.tbl_filter(function(win)
|
2022-07-22 13:29:55 +00:00
|
|
|
return vim.fn.win_gettype(win) ~= 'popup'
|
|
|
|
end, vim.api.nvim_list_wins())
|
|
|
|
end
|
|
|
|
elseif opts.kind == 'tabpage' then
|
2022-07-22 13:30:37 +00:00
|
|
|
if vim.tbl_contains(opts.place, 'statusline') or vim.tbl_contains(opts.place, 'winbar') then
|
|
|
|
wins = vim.tbl_filter(function(win)
|
2022-07-22 13:29:55 +00:00
|
|
|
return vim.fn.win_gettype(win) ~= 'popup'
|
|
|
|
end, vim.api.nvim_tabpage_list_wins(0))
|
|
|
|
end
|
|
|
|
elseif opts.kind == 'window' then
|
2022-07-22 13:30:37 +00:00
|
|
|
wins = { vim.api.nvim_get_current_win() }
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- update them
|
|
|
|
if vim.tbl_contains(opts.place, 'statusline') then
|
|
|
|
for _, win in ipairs(wins) do
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.set('statusline', vim.api.nvim_win_call(win, M.statusline), { window = win })
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if vim.tbl_contains(opts.place, 'winbar') then
|
|
|
|
for _, win in ipairs(wins) do
|
|
|
|
if vim.api.nvim_win_get_height(win) > 1 then
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.set('winbar', vim.api.nvim_win_call(win, M.winbar), { window = win })
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if vim.tbl_contains(opts.place, 'tabline') then
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.set('tabline', vim.api.nvim_win_call(vim.api.nvim_get_current_win(), tabline), { global = true })
|
2022-07-22 13:29:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
vim.g.actual_curwin = old_actual_curwin
|
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
--- Sets &tabline option to lualine
|
2021-03-06 15:03:00 +00:00
|
|
|
local function set_tabline()
|
2022-07-22 13:29:55 +00:00
|
|
|
vim.loop.timer_stop(timers.tal_timer)
|
|
|
|
vim.cmd([[augroup lualine_tal_refresh | exe "autocmd!" | augroup END]])
|
2021-03-17 00:02:13 +00:00
|
|
|
if next(config.tabline) ~= nil then
|
2022-07-22 13:30:37 +00:00
|
|
|
vim.loop.timer_start(
|
|
|
|
timers.tal_timer,
|
|
|
|
0,
|
|
|
|
config.options.refresh.tabline,
|
|
|
|
modules.utils.timer_call(timers.stl_timer, 'lualine_tal_refresh', function()
|
|
|
|
refresh { kind = 'tabpage', place = { 'tabline' }, trigger = 'timer' }
|
|
|
|
end, 3, 'lualine: Failed to refresh tabline')
|
|
|
|
)
|
|
|
|
modules.utils.define_autocmd(
|
|
|
|
default_refresh_events,
|
|
|
|
'*',
|
|
|
|
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['tabline'], 'trigger': 'autocmd'})",
|
|
|
|
'lualine_tal_refresh'
|
|
|
|
)
|
|
|
|
modules.nvim_opts.set('showtabline', 2, { global = true })
|
2022-07-22 13:29:55 +00:00
|
|
|
else
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.restore('tabline', { global = true })
|
|
|
|
modules.nvim_opts.restore('showtabline', { global = true })
|
2021-03-06 15:03:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-30 14:25:05 +00:00
|
|
|
--- Sets &statusline option to lualine
|
2021-10-12 14:04:47 +00:00
|
|
|
--- adds auto command to redraw lualine on VimResized event
|
2021-03-06 15:03:00 +00:00
|
|
|
local function set_statusline()
|
2022-07-22 13:29:55 +00:00
|
|
|
vim.loop.timer_stop(timers.stl_timer)
|
|
|
|
vim.cmd([[augroup lualine_stl_refresh | exe "autocmd!" | augroup END]])
|
2021-03-17 00:02:13 +00:00
|
|
|
if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then
|
2022-07-23 06:53:25 +00:00
|
|
|
if vim.go.statusline == '' then
|
|
|
|
modules.nvim_opts.set('statusline', '%#Normal#', { global = true })
|
|
|
|
end
|
2022-04-28 13:08:08 +00:00
|
|
|
if config.options.globalstatus then
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.set('laststatus', 3, { global = true })
|
|
|
|
vim.loop.timer_start(
|
|
|
|
timers.stl_timer,
|
|
|
|
0,
|
|
|
|
config.options.refresh.statusline,
|
|
|
|
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
|
|
|
|
refresh { kind = 'window', place = { 'statusline' }, trigger = 'timer' }
|
|
|
|
end, 3, 'lualine: Failed to refresh statusline')
|
|
|
|
)
|
|
|
|
modules.utils.define_autocmd(
|
|
|
|
default_refresh_events,
|
|
|
|
'*',
|
|
|
|
"call v:lua.require'lualine'.refresh({'kind': 'window', 'place': ['statusline'], 'trigger': 'autocmd'})",
|
|
|
|
'lualine_stl_refresh'
|
|
|
|
)
|
2022-07-22 13:29:55 +00:00
|
|
|
else
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.set('laststatus', 2, { global = true })
|
|
|
|
vim.loop.timer_start(
|
|
|
|
timers.stl_timer,
|
|
|
|
0,
|
|
|
|
config.options.refresh.statusline,
|
|
|
|
modules.utils.timer_call(timers.stl_timer, 'lualine_stl_refresh', function()
|
|
|
|
refresh { kind = 'tabpage', place = { 'statusline' }, trigger = 'timer' }
|
|
|
|
end, 3, 'lualine: Failed to refresh statusline')
|
|
|
|
)
|
|
|
|
modules.utils.define_autocmd(
|
|
|
|
default_refresh_events,
|
|
|
|
'*',
|
|
|
|
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['statusline'], 'trigger': 'autocmd'})",
|
|
|
|
'lualine_stl_refresh'
|
|
|
|
)
|
2022-04-28 13:08:08 +00:00
|
|
|
end
|
2022-07-22 13:29:55 +00:00
|
|
|
else
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.restore('statusline', { global = true })
|
2022-07-22 13:29:55 +00:00
|
|
|
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.restore('statusline', { window = win })
|
2022-04-28 13:08:08 +00:00
|
|
|
end
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.restore('laststatus', { global = true })
|
2021-08-30 12:22:02 +00:00
|
|
|
end
|
2021-08-16 17:19:56 +00:00
|
|
|
end
|
|
|
|
|
2022-07-22 13:29:55 +00:00
|
|
|
--- Sets &winbar option to lualine
|
|
|
|
local function set_winbar()
|
|
|
|
vim.loop.timer_stop(timers.wb_timer)
|
|
|
|
vim.cmd([[augroup lualine_wb_refresh | exe "autocmd!" | augroup END]])
|
|
|
|
if next(config.winbar) ~= nil or next(config.inactive_winbar) ~= nil then
|
2022-07-22 13:30:37 +00:00
|
|
|
vim.loop.timer_start(
|
|
|
|
timers.stl_timer,
|
|
|
|
0,
|
|
|
|
config.options.refresh.winbar,
|
|
|
|
modules.utils.timer_call(timers.stl_timer, 'lualine_wb_refresh', function()
|
|
|
|
refresh { kind = 'tabpage', place = { 'winbar' }, trigger = 'timer' }
|
|
|
|
end, 3, 'lualine: Failed to refresh winbar')
|
|
|
|
)
|
|
|
|
modules.utils.define_autocmd(
|
|
|
|
default_refresh_events,
|
|
|
|
'*',
|
|
|
|
"call v:lua.require'lualine'.refresh({'kind': 'tabpage', 'place': ['winbar'], 'trigger': 'autocmd'})",
|
|
|
|
'lualine_wb_refresh'
|
|
|
|
)
|
2022-07-22 13:29:55 +00:00
|
|
|
elseif vim.fn.has('nvim-0.8') == 1 then
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.restore('winbar', { global = true })
|
2022-07-22 13:29:55 +00:00
|
|
|
for _, win in ipairs(vim.api.nvim_list_wins()) do
|
2022-07-22 13:30:37 +00:00
|
|
|
modules.nvim_opts.restore('winbar', { window = win })
|
2021-08-16 17:19:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-12 14:04:47 +00:00
|
|
|
-- lualine.setup function
|
|
|
|
--- sets new user config
|
2022-05-30 14:25:05 +00:00
|
|
|
--- This function doesn't load components/theme etc... They are done before
|
|
|
|
--- first statusline redraw and after new config. This is more efficient when
|
|
|
|
--- lualine config is done in several setup calls as chunks. This way
|
|
|
|
--- we don't initialize components just to throw them away. Instead they are
|
2021-10-12 14:04:47 +00:00
|
|
|
--- initialized when we know we will use them.
|
2022-05-30 14:25:05 +00:00
|
|
|
--- sets &last_status to 2
|
2021-10-12 14:04:47 +00:00
|
|
|
---@param user_config table table
|
2021-08-16 17:19:56 +00:00
|
|
|
local function setup(user_config)
|
2022-03-07 15:49:22 +00:00
|
|
|
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
|
2022-03-18 00:59:01 +00:00
|
|
|
config = modules.config_module.apply_configuration(user_config)
|
2022-03-07 15:49:22 +00:00
|
|
|
vim.cmd([[augroup lualine | exe "autocmd!" | augroup END]])
|
|
|
|
setup_theme()
|
|
|
|
-- load components & extensions
|
|
|
|
modules.loader.load_all(config)
|
|
|
|
set_statusline()
|
|
|
|
set_tabline()
|
2022-07-22 13:29:55 +00:00
|
|
|
set_winbar()
|
2022-03-07 15:49:22 +00:00
|
|
|
if package.loaded['lualine.utils.notices'] then
|
|
|
|
modules.utils_notices.notice_message_startup()
|
|
|
|
end
|
2020-12-30 14:48:51 +00:00
|
|
|
end
|
|
|
|
|
2022-07-22 13:29:55 +00:00
|
|
|
M = {
|
2021-08-04 01:13:37 +00:00
|
|
|
setup = setup,
|
2022-07-22 13:29:55 +00:00
|
|
|
statusline = status_dispatch('sections'),
|
2021-08-04 01:13:37 +00:00
|
|
|
tabline = tabline,
|
2021-08-17 07:26:44 +00:00
|
|
|
get_config = modules.config_module.get_config,
|
2022-07-22 13:29:55 +00:00
|
|
|
refresh = refresh,
|
|
|
|
winbar = status_dispatch('winbar'),
|
2021-08-04 01:13:37 +00:00
|
|
|
}
|
2022-07-22 13:29:55 +00:00
|
|
|
|
|
|
|
return M
|