|DEPRECATION| enhance(themes): Auto colorscheme detection and more

- `auto` theme now auto loads available theme for colorschme based on
  g:color_name . If that fails then it generates a theme for that
  colorschme like before.
- Theme from external source is preferred over bundled version in
  lualine . This means if user has a colorschme that provided the same
  theme as lualine the one from colorschme will be loaded.
- Default value of theme is changed to `auto` from `gruvbox`.
- Now when users theme from config fails lualine will fallbavk to
  `auto`. If `auto` fails then lualine will fallback to `gruvbox`
- Some themes have been renamed to their actual name (g:color_name).
  older names have been deprecated. [DEPRECATION]
    oceanicnext -> OceanicNext
    papercolor -> PaperColor
    tomorrow -> Tomorrow
    gruvbox_material -> gruvbox-material
    modus_vivendi -> modus-vivendi
- A few more adaptive themes added (aye, gruvbox, iceberg)
- Updated THEMES.md to reflect changes in theme name
This commit is contained in:
shadmansaleh 2021-08-14 12:02:30 +06:00
parent 570e68095e
commit 32727039a9
15 changed files with 181 additions and 61 deletions

View File

@ -37,6 +37,10 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648541-cbb0cc80-74bb-11eb-843f-19c4c58b1d91.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648541-cbb0cc80-74bb-11eb-843f-19c4c58b1d91.png'/>
</p> </p>
### ayu
It's a combination of ayu_light, ayu_dark & ayu_mirage. It loads one of these
them based you your `g:ayucolor` option.
### 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'/>
@ -61,7 +65,7 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648675-22b6a180-74bc-11eb-9b8e-45e64a03e062.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648675-22b6a180-74bc-11eb-9b8e-45e64a03e062.png'/>
</p> </p>
### gruvbox ### gruvbox_dark
<p> <p>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648685-2b0edc80-74bc-11eb-9ec9-9aac3677df43.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648685-2b0edc80-74bc-11eb-9ec9-9aac3677df43.png'/>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648693-2ea26380-74bc-11eb-831a-9ebbe4f3dd83.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648693-2ea26380-74bc-11eb-831a-9ebbe4f3dd83.png'/>
@ -77,7 +81,11 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/34294427/118757020-5ffdb600-b896-11eb-95e7-dbf1f08e063d.png'/> <img width='700' src='https://user-images.githubusercontent.com/34294427/118757020-5ffdb600-b896-11eb-95e7-dbf1f08e063d.png'/>
</p> </p>
### gruvbox_material ### gruvbox
It's a combination of gruvbox_light and gruvbox_dark. It loads either of
them based you your `background` option.
### gruvbox-material
<p> <p>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648725-3f52d980-74bc-11eb-8fa5-a77b0a21cdea.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648725-3f52d980-74bc-11eb-8fa5-a77b0a21cdea.png'/>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648728-41b53380-74bc-11eb-99cf-001eab6cc51b.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648728-41b53380-74bc-11eb-99cf-001eab6cc51b.png'/>
@ -109,6 +117,10 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648862-7aeda380-74bc-11eb-808c-1b12dde45f3d.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648862-7aeda380-74bc-11eb-808c-1b12dde45f3d.png'/>
</p> </p>
### iceberg
It's a combination of icrberg_light and icrberg_dark. It loads either of
them based you your `background` option.
### jellybeans ### jellybeans
<p> <p>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648882-82ad4800-74bc-11eb-91e8-4d38fcdec134.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648882-82ad4800-74bc-11eb-91e8-4d38fcdec134.png'/>
@ -125,7 +137,7 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/41551030/108648935-a2dd0700-74bc-11eb-9a4b-72eb1e2ab79e.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108648935-a2dd0700-74bc-11eb-9a4b-72eb1e2ab79e.png'/>
</p> </p>
### modus_vivendi ### modus-vivendi
<p> <p>
<img width='700' src='https://user-images.githubusercontent.com/9327361/114389966-58176b80-9b9e-11eb-944e-1e0079527d74.png'/> <img width='700' src='https://user-images.githubusercontent.com/9327361/114389966-58176b80-9b9e-11eb-944e-1e0079527d74.png'/>
<img width='700' src='https://user-images.githubusercontent.com/9327361/114390000-606fa680-9b9e-11eb-97dd-ef5bbc23049a.png'/> <img width='700' src='https://user-images.githubusercontent.com/9327361/114390000-606fa680-9b9e-11eb-97dd-ef5bbc23049a.png'/>
@ -157,7 +169,7 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649021-cf911e80-74bc-11eb-8b4a-9f9eb61c7973.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649021-cf911e80-74bc-11eb-8b4a-9f9eb61c7973.png'/>
</p> </p>
### oceanicnext ### OceanicNext
<p> <p>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649039-d7e95980-74bc-11eb-9a33-df413936c645.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649039-d7e95980-74bc-11eb-9a33-df413936c645.png'/>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649043-d91a8680-74bc-11eb-9b1b-9c2e88ede3aa.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649043-d91a8680-74bc-11eb-9b1b-9c2e88ede3aa.png'/>
@ -205,6 +217,10 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649137-0cf5ac00-74bd-11eb-8764-765bead5de6e.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649137-0cf5ac00-74bd-11eb-8764-765bead5de6e.png'/>
</p> </p>
### PaperColor
It's a combination of papercolor_light and papercolor_dark. It loads either of
them based you your `background` option.
### powerline ### powerline
<p> <p>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649147-14b55080-74bd-11eb-9670-713185342eb2.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649147-14b55080-74bd-11eb-9670-713185342eb2.png'/>
@ -237,7 +253,7 @@ lualine try to match your colorscheme.
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649258-48907600-74bd-11eb-9bba-8e82b56777d9.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649258-48907600-74bd-11eb-9bba-8e82b56777d9.png'/>
</p> </p>
### tomorrow ### Tomorrow
<p> <p>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649275-51814780-74bd-11eb-881b-1e137a0cbfe0.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649275-51814780-74bd-11eb-881b-1e137a0cbfe0.png'/>
<img width='700' src='https://user-images.githubusercontent.com/41551030/108649297-59d98280-74bd-11eb-92a5-a8c4af150106.png'/> <img width='700' src='https://user-images.githubusercontent.com/41551030/108649297-59d98280-74bd-11eb-92a5-a8c4af150106.png'/>

View File

@ -3,7 +3,7 @@
local config = { local config = {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = 'gruvbox', theme = 'auto',
component_separators = {'', ''}, component_separators = {'', ''},
section_separators = {'', ''}, section_separators = {'', ''},
disabled_filetypes = {} disabled_filetypes = {}

View File

@ -171,20 +171,74 @@ end
local function tabline() return statusline(config.tabline, true) end local function tabline() return statusline(config.tabline, true) end
local function check_theme_name_deprecation(theme_name)
local deprection_table = {
oceanicnext = 'OceanicNext',
papercolor = 'PaperColor',
tomorrow = 'Tomorrow',
gruvbox_material = 'gruvbox-material',
modus_vivendi = 'modus-vivendi',
}
if deprection_table[theme_name] then
local correct_name = deprection_table[theme_name]
utils_notices.add_notice(string.format([[
### options.theme
You're using `%s` as theme name .
It has recently been renamed to `%s`.
Please update your config to follow that.
You have something like this in your config.
```lua
options = {
theme = '%s'
}
```
You'll have to change it to something like this.
```lua
options = {
theme = '%s'
}
```
]], theme_name, correct_name, theme_name, correct_name))
return correct_name
end
return theme_name
end
local function notify_theme_error(theme_name)
local message_template = theme_name ~= 'auto' and [[
### options.theme
Theme `%s` not found, falling back to `auto`. Check if spelling is right.
]] or [[
### options.theme
Theme `%s` failed, falling back to `gruvbox`.
This shouldn't happen.
Please report the issue at https://github.com/shadmansaleh/lualine.nvim/issues .
Also provide what colorscheme you're using.
]]
utils_notices.add_notice(string.format(message_template, theme_name))
end
local function setup_theme() local function setup_theme()
local function get_theme_from_config() local function get_theme_from_config()
local theme_name = config.options.theme local theme_name = config.options.theme
if type(theme_name) == 'string' then if type(theme_name) == 'string' then
package.loaded['lualine.themes.'..theme_name] = nil theme_name = check_theme_name_deprecation(theme_name)
local ok, theme = pcall(require, 'lualine.themes.' .. theme_name) local ok, theme = pcall(loader.load_theme, theme_name)
if ok then return theme end if ok and theme then return theme end
elseif type(theme_name) == 'table' then elseif type(theme_name) == 'table' then
-- use the provided theme as-is -- use the provided theme as-is
return config.options.theme return config.options.theme
end end
vim.api.nvim_err_writeln('theme ' .. tostring(theme_name) .. if theme_name ~= 'auto' then
' not found, defaulting to gruvbox') notify_theme_error(theme_name)
return require 'lualine.themes.gruvbox' local ok, theme = pcall(loader.load_theme, 'auto')
if ok and theme then return theme end
end
notify_theme_error('auto')
return loader.load_theme('gruvbox')
end end
local theme = get_theme_from_config() local theme = get_theme_from_config()
highlight.create_highlight_groups(theme) highlight.create_highlight_groups(theme)

View File

@ -1,4 +1,13 @@
local utils = require 'lualine.utils.utils' local utils = require 'lualine.utils.utils'
local loader = require 'lualine.utils.loader'
local color_name = vim.g.colors_name
if color_name then
-- Check if there's a theme for current colorscheme
-- If there is load that instead of genarating a new one
local ok, theme = pcall(loader.load_theme, color_name)
if ok and theme then return theme end
end
--------------- ---------------
-- Constents -- -- Constents --

View File

@ -0,0 +1,7 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
-- Credit: itchyny(lightline)
-- License: MIT License
local style = vim.g.ayucolor or 'dark'
return require('lualine.themes.ayu_' .. style)

View File

@ -1,48 +1,7 @@
-- Copyright (c) 2020-2021 hoob3rt -- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
-- LuaFormatter off -- Credit: itchyny(lightline)
local colors = { -- License: MIT License
black = '#282828', local background = vim.opt.background:get()
white = '#ebdbb2',
red = '#fb4934', return require('lualine.themes.gruvbox_' .. background)
green = '#b8bb26',
blue = '#83a598',
yellow = '#fe8019',
gray = '#a89984',
darkgray = '#3c3836',
lightgray = '#504945',
inactivegray = '#7c6f64',
}
-- LuaFormatter on
return {
normal = {
a = {bg = colors.gray, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.darkgray, fg = colors.gray}
},
insert = {
a = {bg = colors.blue, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.lightgray, fg = colors.white}
},
visual = {
a = {bg = colors.yellow, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.inactivegray, fg = colors.black}
},
replace = {
a = {bg = colors.red, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.black, fg = colors.white}
},
command = {
a = {bg = colors.green, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.inactivegray, fg = colors.black}
},
inactive = {
a = {bg = colors.darkgray, fg = colors.gray, gui = 'bold'},
b = {bg = colors.darkgray, fg = colors.gray},
c = {bg = colors.darkgray, fg = colors.gray}
}
}

View File

@ -0,0 +1,48 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
-- LuaFormatter off
local colors = {
black = '#282828',
white = '#ebdbb2',
red = '#fb4934',
green = '#b8bb26',
blue = '#83a598',
yellow = '#fe8019',
gray = '#a89984',
darkgray = '#3c3836',
lightgray = '#504945',
inactivegray = '#7c6f64',
}
-- LuaFormatter on
return {
normal = {
a = {bg = colors.gray, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.darkgray, fg = colors.gray}
},
insert = {
a = {bg = colors.blue, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.lightgray, fg = colors.white}
},
visual = {
a = {bg = colors.yellow, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.inactivegray, fg = colors.black}
},
replace = {
a = {bg = colors.red, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.black, fg = colors.white}
},
command = {
a = {bg = colors.green, fg = colors.black, gui = 'bold'},
b = {bg = colors.lightgray, fg = colors.white},
c = {bg = colors.inactivegray, fg = colors.black}
},
inactive = {
a = {bg = colors.darkgray, fg = colors.gray, gui = 'bold'},
b = {bg = colors.darkgray, fg = colors.gray},
c = {bg = colors.darkgray, fg = colors.gray}
}
}

View File

@ -0,0 +1,7 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
-- Credit: itchyny(lightline)
-- License: MIT License
local background = vim.opt.background:get()
return require('lualine.themes.iceberg_' .. background)

View File

@ -75,4 +75,24 @@ local function load_all(config)
load_extensions(config) load_extensions(config)
end end
return {load_all = load_all} local function load(patern)
local files = vim.fn.uniq(vim.api.nvim_get_runtime_file(patern, true))
local n_files = #files
if n_files == 0 then return nil
elseif n_files == 1 then return dofile(files[1])
else
for _, file in ipairs(files) do
if not file:find('lualine.nvim') then return dofile(file) end
end
end
end
local function load_theme(theme_name)
return load(table.concat(
{'lua', 'lualine', 'themes', theme_name..'.lua'}, package.config:sub(1, 1)))
end
return {
load_all = load_all,
load_theme = load_theme
}

View File

@ -19,7 +19,7 @@ describe('config parsing', function()
describe('theme', function() describe('theme', function()
it('default', function() it('default', function()
local config = config_module.apply_configuration({}) local config = config_module.apply_configuration({})
eq(config.options.theme, 'gruvbox') eq(config.options.theme, 'auto')
end) end)
it('custom', function() it('custom', function()
local config = {options = {theme = 'nord'}} local config = {options = {theme = 'nord'}}