Add support for bufferline

This commit is contained in:
Olivier Roques
2020-12-26 15:20:27 +01:00
parent d9993f23ca
commit ea75fdbb69
9 changed files with 220 additions and 79 deletions

View File

@@ -1,4 +1,4 @@
local cmd, fn, vim = vim.cmd, vim.fn, vim
local cmd, fn = vim.cmd, vim.fn
local g = vim.g
local M = {}
@@ -27,14 +27,30 @@ function M.is_active()
return g.statusline_winid == fn.win_getid()
end
function M.get_state(class)
if class == 'mode' and M.is_active() then
function M.get_state(section)
if section.class == 'mode' and M.is_active() then
local mode = M.modes[fn.mode()] or M.modes['?']
return mode.state
end
if section.class == 'bufferline' then
if section.conceal then return 'conceal' end
local state = {}
table.insert(state, section.current and 'current' or 'background')
if section.modified then table.insert(state, 'modified') end
return table.concat(state, '_')
end
return M.is_active() and 'active' or 'inactive'
end
function M.color(section)
if type(section) ~= 'table' then return section end
if section.class == 'none' then return section.item end
local state = M.get_state(section)
local hlgroup = string.format('Hardline_%s_%s', section.class, state)
if fn.hlexists(hlgroup) == 0 then return section.item end
return string.format('%%#%s#%s%%*', hlgroup, section.item)
end
function M.set_cache(augroup)
cmd(string.format('augroup %s', augroup))
cmd('autocmd!')