This reverts commit 141417de61
.
This commit is contained in:
parent
8572db014a
commit
d3cc343053
|
@ -1,10 +1,11 @@
|
||||||
-- 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 M = {}
|
local M = {}
|
||||||
local cterm_colors
|
local utils_colors = require 'lualine.utils.cterm_colors'
|
||||||
local utils = require 'lualine.utils.utils'
|
local utils = require 'lualine.utils.utils'
|
||||||
local section_highlight_map = {x = 'c', y = 'b', z = 'a'}
|
local section_highlight_map = {x = 'c', y = 'b', z = 'a'}
|
||||||
local active_theme = nil
|
local active_theme = nil
|
||||||
|
local cterm_colors = false
|
||||||
|
|
||||||
function M.highlight(name, foreground, background, gui, reload)
|
function M.highlight(name, foreground, background, gui, reload)
|
||||||
local command = {'highlight', name}
|
local command = {'highlight', name}
|
||||||
|
@ -12,14 +13,14 @@ function M.highlight(name, foreground, background, gui, reload)
|
||||||
table.insert(command, 'guifg=' .. foreground)
|
table.insert(command, 'guifg=' .. foreground)
|
||||||
if cterm_colors then
|
if cterm_colors then
|
||||||
table.insert(command,
|
table.insert(command,
|
||||||
'ctermfg=' .. cterm_colors.get_cterm_color(foreground))
|
'ctermfg=' .. utils_colors.get_cterm_color(foreground))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if background and background ~= 'none' then
|
if background and background ~= 'none' then
|
||||||
table.insert(command, 'guibg=' .. background)
|
table.insert(command, 'guibg=' .. background)
|
||||||
if cterm_colors then
|
if cterm_colors then
|
||||||
table.insert(command,
|
table.insert(command,
|
||||||
'ctermbg=' .. cterm_colors.get_cterm_color(background))
|
'ctermbg=' .. utils_colors.get_cterm_color(background))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if gui then
|
if gui then
|
||||||
|
@ -35,9 +36,7 @@ end
|
||||||
function M.create_highlight_groups(theme)
|
function M.create_highlight_groups(theme)
|
||||||
utils.clear_highlights()
|
utils.clear_highlights()
|
||||||
active_theme = theme
|
active_theme = theme
|
||||||
if not vim.o.termguicolors then
|
cterm_colors = not vim.o.termguicolors
|
||||||
cterm_colors = require 'lualine.utils.cterm_colors'
|
|
||||||
end
|
|
||||||
for mode, sections in pairs(theme) do
|
for mode, sections in pairs(theme) do
|
||||||
for section, colorscheme in pairs(sections) do
|
for section, colorscheme in pairs(sections) do
|
||||||
local highlight_group_name = {'lualine', section, mode}
|
local highlight_group_name = {'lualine', section, mode}
|
||||||
|
|
|
@ -5,6 +5,7 @@ local highlight = require('lualine.highlight')
|
||||||
local config = {}
|
local config = {}
|
||||||
|
|
||||||
local function apply_configuration(config_table)
|
local function apply_configuration(config_table)
|
||||||
|
if not config_table then return end
|
||||||
local function parse_sections(section_group_name)
|
local function parse_sections(section_group_name)
|
||||||
if not config_table[section_group_name] then return end
|
if not config_table[section_group_name] then return end
|
||||||
for section_name, section in pairs(config_table[section_group_name]) do
|
for section_name, section in pairs(config_table[section_group_name]) do
|
||||||
|
@ -80,23 +81,18 @@ local function component_loader(component)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function load_sections(sections)
|
local function load_sections(sections)
|
||||||
local async_loader
|
for section_name, section in pairs(sections) do
|
||||||
async_loader = vim.loop.new_async(vim.schedule_wrap(function()
|
for index, component in pairs(section) do
|
||||||
for section_name, section in pairs(sections) do
|
if type(component) == 'string' or type(component) == 'function' then
|
||||||
for index, component in pairs(section) do
|
component = {component}
|
||||||
if type(component) == 'string' or type(component) == 'function' then
|
|
||||||
component = {component}
|
|
||||||
end
|
|
||||||
component.self = {}
|
|
||||||
component.self.section = section_name
|
|
||||||
-- apply default args
|
|
||||||
component = vim.tbl_extend('keep', component, config.options)
|
|
||||||
section[index] = component_loader(component)
|
|
||||||
end
|
end
|
||||||
|
component.self = {}
|
||||||
|
component.self.section = section_name
|
||||||
|
-- apply default args
|
||||||
|
component = vim.tbl_extend('keep', component, config.options)
|
||||||
|
section[index] = component_loader(component)
|
||||||
end
|
end
|
||||||
async_loader:close()
|
end
|
||||||
end))
|
|
||||||
async_loader:send()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function load_components()
|
local function load_components()
|
||||||
|
@ -238,36 +234,31 @@ end
|
||||||
local function tabline() return statusline(config.tabline, true) end
|
local function tabline() return statusline(config.tabline, true) end
|
||||||
|
|
||||||
local function setup_theme()
|
local function setup_theme()
|
||||||
local async_loader
|
local function get_theme_from_config()
|
||||||
async_loader = vim.loop.new_async(vim.schedule_wrap(function()
|
local theme_name = config.options.theme
|
||||||
local function get_theme_from_config()
|
if type(theme_name) == 'string' then
|
||||||
local theme_name = config.options.theme
|
local ok, theme = pcall(require, 'lualine.themes.' .. theme_name)
|
||||||
if type(theme_name) == 'string' then
|
if ok then return theme end
|
||||||
local ok, theme = pcall(require, 'lualine.themes.' .. theme_name)
|
elseif type(theme_name) == 'table' then
|
||||||
if ok then return theme end
|
-- use the provided theme as-is
|
||||||
elseif type(theme_name) == 'table' then
|
return config.options.theme
|
||||||
-- use the provided theme as-is
|
|
||||||
return config.options.theme
|
|
||||||
end
|
|
||||||
vim.api.nvim_echo({
|
|
||||||
{
|
|
||||||
'theme ' .. tostring(theme_name) .. ' not found, defaulting to gruvbox',
|
|
||||||
'ErrorMsg'
|
|
||||||
}
|
|
||||||
}, true, {})
|
|
||||||
return require 'lualine.themes.gruvbox'
|
|
||||||
end
|
end
|
||||||
local theme = get_theme_from_config()
|
vim.api.nvim_echo({
|
||||||
highlight.create_highlight_groups(theme)
|
{
|
||||||
vim.api.nvim_exec([[
|
'theme ' .. tostring(theme_name) .. ' not found, defaulting to gruvbox',
|
||||||
augroup lualine
|
'ErrorMsg'
|
||||||
autocmd!
|
}
|
||||||
autocmd ColorScheme * lua require'lualine.utils.utils'.reload_highlights()
|
}, true, {})
|
||||||
augroup END
|
return require 'lualine.themes.gruvbox'
|
||||||
]], false)
|
end
|
||||||
async_loader:close()
|
local theme = get_theme_from_config()
|
||||||
end))
|
highlight.create_highlight_groups(theme)
|
||||||
async_loader:send()
|
vim.api.nvim_exec([[
|
||||||
|
augroup lualine
|
||||||
|
autocmd!
|
||||||
|
autocmd ColorScheme * lua require'lualine.utils.utils'.reload_highlights()
|
||||||
|
augroup END
|
||||||
|
]], false)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_tabline()
|
local function set_tabline()
|
||||||
|
@ -281,10 +272,8 @@ 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.o.statusline = '%!v:lua.require\'lualine\'.statusline()'
|
vim.o.statusline = '%!v:lua.require\'lualine\'.statusline()'
|
||||||
vim.api.nvim_exec([[
|
vim.api.nvim_exec([[
|
||||||
augroup lualine
|
autocmd lualine WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline()
|
||||||
autocmd WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline()
|
autocmd lualine WinEnter,BufEnter * set statusline<
|
||||||
autocmd WinEnter,BufEnter * set statusline<
|
|
||||||
augroup END
|
|
||||||
]], false)
|
]], false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,9 +7,6 @@ function M.draw_section(section, highlight_name)
|
||||||
local status = {}
|
local status = {}
|
||||||
for _, component in pairs(section) do
|
for _, component in pairs(section) do
|
||||||
-- load components into status table
|
-- load components into status table
|
||||||
if type(component) ~= 'table' or (type(component) == 'table' and not component.component_no) then
|
|
||||||
return '' -- unknown element in section. section posibly not yet loaded
|
|
||||||
end
|
|
||||||
table.insert(status, component:draw(highlight_name))
|
table.insert(status, component:draw(highlight_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue