feat(themes): add automatic theme for nvim-base16 colorschemes(#597)
This commit is contained in:
parent
c8e5a69085
commit
f3dc0dcd4c
12
THEMES.md
12
THEMES.md
@ -46,6 +46,18 @@ load ayu_light when background=light and ayu_dark when background=dark
|
|||||||
But if `g:ayuprefermirage` exists, it will load ayu_mirage instead when
|
But if `g:ayuprefermirage` exists, it will load ayu_mirage instead when
|
||||||
`background=dark`.
|
`background=dark`.
|
||||||
|
|
||||||
|
### base16
|
||||||
|
|
||||||
|
This theme will automatically uses colors defined by your colorscheme using [RRethy/nvim-base16](https://github.com/RRethy/nvim-base16)] plugin.
|
||||||
|
The following example is using the `tomorrow-night` colorscheme:
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<img width='700' src='https://user-images.githubusercontent.com/11501572/156889654-3dedc9a1-e7a5-4cbe-b219-2a97499cf1d2.png'/>
|
||||||
|
<img width='700' src='https://user-images.githubusercontent.com/11501572/156889648-93bf3ce8-064d-4ac0-8415-20d6ef87c60b.png'/>
|
||||||
|
<img width='700' src='https://user-images.githubusercontent.com/11501572/156889624-c97fc3ae-d642-41ba-b39a-f9a72ff8b15e.png'/>
|
||||||
|
<img width='700' src='https://user-images.githubusercontent.com/11501572/156889566-17066e95-7f85-4bfd-8178-c4a34beab453.png'/>
|
||||||
|
</p>
|
||||||
|
|
||||||
### codedark
|
### codedark
|
||||||
<p>
|
<p>
|
||||||
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648568-dff4c980-74bb-11eb-9d16-b68ac68f2ab2.png'/>
|
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648568-dff4c980-74bb-11eb-9d16-b68ac68f2ab2.png'/>
|
||||||
|
@ -5,6 +5,11 @@ local loader = require('lualine.utils.loader')
|
|||||||
|
|
||||||
local color_name = vim.g.colors_name
|
local color_name = vim.g.colors_name
|
||||||
if color_name then
|
if color_name then
|
||||||
|
-- All base16 colorschemes share the same theme
|
||||||
|
if 'base16' == color_name:sub(1, 6) then
|
||||||
|
color_name = 'base16'
|
||||||
|
end
|
||||||
|
|
||||||
-- Check if there's a theme for current colorscheme
|
-- Check if there's a theme for current colorscheme
|
||||||
-- If there is load that instead of genarating a new one
|
-- If there is load that instead of genarating a new one
|
||||||
local ok, theme = pcall(loader.load_theme, color_name)
|
local ok, theme = pcall(loader.load_theme, color_name)
|
||||||
|
92
lua/lualine/themes/base16.lua
Normal file
92
lua/lualine/themes/base16.lua
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
local modules = require('lualine_require').lazy_require({ notices = 'lualine.utils.notices' })
|
||||||
|
|
||||||
|
local function add_notice(notice)
|
||||||
|
modules.notices.add_notice('theme(base16): ' .. notice)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setup(colors)
|
||||||
|
local theme = {
|
||||||
|
normal = {
|
||||||
|
a = { fg = colors.bg, bg = colors.normal },
|
||||||
|
b = { fg = colors.light_fg, bg = colors.alt_bg },
|
||||||
|
c = { fg = colors.fg, bg = colors.bg },
|
||||||
|
},
|
||||||
|
replace = {
|
||||||
|
a = { fg = colors.bg, bg = colors.replace },
|
||||||
|
b = { fg = colors.light_fg, bg = colors.alt_bg },
|
||||||
|
},
|
||||||
|
insert = {
|
||||||
|
a = { fg = colors.bg, bg = colors.insert },
|
||||||
|
b = { fg = colors.light_fg, bg = colors.alt_bg },
|
||||||
|
},
|
||||||
|
visual = {
|
||||||
|
a = { fg = colors.bg, bg = colors.visual },
|
||||||
|
b = { fg = colors.light_fg, bg = colors.alt_bg },
|
||||||
|
},
|
||||||
|
inactive = {
|
||||||
|
a = { fg = colors.dark_fg, bg = colors.bg },
|
||||||
|
b = { fg = colors.dark_fg, bg = colors.bg },
|
||||||
|
c = { fg = colors.dark_fg, bg = colors.bg },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
theme.command = theme.normal
|
||||||
|
theme.terminal = theme.insert
|
||||||
|
|
||||||
|
return theme
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setup_default()
|
||||||
|
return setup {
|
||||||
|
bg = '#282a2e',
|
||||||
|
alt_bg = '#373b41',
|
||||||
|
dark_fg = '#969896',
|
||||||
|
fg = '#b4b7b4',
|
||||||
|
light_fg = '#c5c8c6',
|
||||||
|
normal = '#81a2be',
|
||||||
|
insert = '#b5bd68',
|
||||||
|
visual = '#b294bb',
|
||||||
|
replace = '#de935f',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function setup_base16()
|
||||||
|
local loaded, base16 = pcall(require, 'base16-colorscheme')
|
||||||
|
|
||||||
|
if not loaded then
|
||||||
|
add_notice(
|
||||||
|
'nvim-base16 is not currently present in your runtimepath, make sure it is properly installed,'
|
||||||
|
.. ' fallback to default colors.'
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if not base16.colors and not vim.env.BASE16_THEME then
|
||||||
|
add_notice(
|
||||||
|
'nvim-base16 is not loaded yet, you should update your configuration to load it before lualine'
|
||||||
|
.. ' so that the colors from your colorscheme can be used, fallback to "tomorrow-night" theme.'
|
||||||
|
)
|
||||||
|
elseif not base16.colors and not base16.colorschemes[vim.env.BASE16_THEME] then
|
||||||
|
add_notice(
|
||||||
|
'The colorscheme "%s" defined by the environment variable "BASE16_THEME" is not handled by'
|
||||||
|
.. ' nvim-base16, fallback to "tomorrow-night" theme.'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local colors = base16.colors or base16.colorschemes[vim.env.BASE16_THEME or 'tomorrow-night']
|
||||||
|
|
||||||
|
return setup {
|
||||||
|
bg = colors.base01,
|
||||||
|
alt_bg = colors.base02,
|
||||||
|
dark_fg = colors.base03,
|
||||||
|
fg = colors.base04,
|
||||||
|
light_fg = colors.base05,
|
||||||
|
normal = colors.base0D,
|
||||||
|
insert = colors.base0B,
|
||||||
|
visual = colors.base0E,
|
||||||
|
replace = colors.base09,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
return setup_base16() or setup_default()
|
Loading…
x
Reference in New Issue
Block a user