refactor theme

This commit is contained in:
mvllow 2021-08-20 11:06:35 -05:00
commit 5d560dfb11
2 changed files with 292 additions and 328 deletions

View file

@ -1,9 +1,68 @@
local p = require('rose-pine.palette') local p = require('rose-pine.palette')
local theme = {} local theme = {}
local maybe_base = p.base
if vim.g.rose_pine_disable_background then
maybe_base = p.none
end
theme.base = {
ColorColumn = { bg = p.highlight_overlay },
-- Conceal = {},
-- Cursor = {},
CursorColumn = { bg = p.highlight },
-- CursorIM = {},
CursorLine = { bg = p.highlight_inactive },
CursorLineNr = { fg = p.text },
DarkenedPanel = { bg = p.surface },
DarkenedStatusline = { bg = p.surface },
DiffAdd = { fg = p.foam },
DiffChange = { fg = p.rose },
DiffDelete = { fg = p.love },
DiffText = { fg = p.text },
Directory = { fg = p.foam, bg = p.none },
-- EndOfBuffer = {},
ErrorMsg = { fg = p.love, style = 'bold' },
FloatBorder = { fg = p.highlight, bg = p.surface },
FoldColumn = {},
Folded = { fg = p.text, bg = p.surface },
IncSearch = { bg = p.highlight },
LineNr = { fg = p.inactive },
MatchParen = { fg = p.text, bg = p.overlay },
-- ModeMsg = {},
MoreMsg = { fg = p.iris },
NonText = { fg = p.inactive },
Normal = { fg = p.text, bg = maybe_base },
-- NormalFloat = {},
Pmenu = { fg = p.subtle, bg = p.surface },
PmenuSbar = { bg = p.overlay },
PmenuSel = { fg = p.text, bg = p.overlay },
PmenuThumb = { bg = p.inactive },
Question = { fg = p.gold },
-- QuickFixLine = {},
Search = { fg = p.iris, bg = p.highlight_overlay },
SpecialKey = { fg = p.foam },
SpellBad = { style = 'undercurl', sp = p.love },
SpellCap = { style = 'undercurl', sp = p.subtle },
SpellLocal = { style = 'undercurl', sp = p.subtle },
SpellRare = { style = 'undercurl', sp = p.subtle },
SignColumn = { fg = p.text, bg = maybe_base },
StatusLine = { fg = p.text, bg = p.surface },
StatusLineNC = { fg = p.subtle, bg = p.surface },
-- StatusLineTerm = {},
-- StatusLineTermNC = {},
-- TabLine = {},
-- TabLineFill = {},
-- TabLineSel = {},
Title = { fg = p.rose },
VertSplit = { fg = p.overlay },
Visual = { bg = p.highlight },
-- VisualNOS = {},
WarningMsg = { fg = p.gold },
-- Whitespace = {},
-- WildMenu = {},
theme.loadSyntax = function()
local syntax = {
Boolean = { fg = p.gold }, Boolean = { fg = p.gold },
Character = { fg = p.gold }, Character = { fg = p.gold },
Comment = { Comment = {
@ -38,94 +97,49 @@ theme.loadSyntax = function()
String = { fg = p.gold }, String = { fg = p.gold },
Structure = { fg = p.foam }, Structure = { fg = p.foam },
Tag = { fg = p.rose }, Tag = { fg = p.rose },
Title = { fg = p.text },
Todo = { fg = p.iris }, Todo = { fg = p.iris },
Type = { fg = p.foam }, Type = { fg = p.foam },
Typedef = { fg = p.foam }, Typedef = { fg = p.foam },
Underlined = { fg = p.foam, style = 'underline' }, Underlined = { fg = p.foam, style = 'underline' },
-- html
htmlArg = { fg = p.iris }, htmlArg = { fg = p.iris },
htmlEndTag = { fg = p.subtle }, htmlEndTag = { fg = p.subtle },
htmlLink = { fg = p.text }, htmlLink = { fg = p.text },
htmlTag = { fg = p.subtle }, htmlTag = { fg = p.subtle },
htmlTagN = { fg = p.love }, htmlTagN = { fg = p.love },
htmlTagName = { fg = p.foam }, htmlTagName = { fg = p.foam },
LspDiagnosticsDefaultHint = { fg = p.iris },
LspDiagnosticsDefaultInformation = { fg = p.foam },
LspDiagnosticsDefaultWarning = { fg = p.gold },
LspDiagnosticsDefaultError = { fg = p.love },
LspDiagnosticsFloatingHint = { fg = p.iris },
LspDiagnosticsFloatingInformation = { fg = p.foam },
LspDiagnosticsFloatingWarning = { fg = p.gold },
LspDiagnosticsFloatingError = { fg = p.love },
LspDiagnosticsSignHint = { fg = p.iris },
LspDiagnosticsSignInformation = { fg = p.foam },
LspDiagnosticsSignWarning = { fg = p.gold },
LspDiagnosticsSignError = { fg = p.love },
LspDiagnosticsUnderlineHint = { style = 'undercurl', sp = p.iris },
LspDiagnosticsUnderlineInformation = { style = 'undercurl', sp = p.foam },
LspDiagnosticsUnderlineWarning = { style = 'undercurl', sp = p.gold },
LspDiagnosticsUnderlineError = { style = 'undercurl', sp = p.love },
LspDiagnosticsVirtualTextHint = { fg = p.iris },
LspDiagnosticsVirtualTextInformation = { fg = p.foam },
LspDiagnosticsVirtualTextWarning = { fg = p.gold },
LspDiagnosticsVirtualTextError = { fg = p.love },
LspReferenceText = { fg = p.rose, bg = p.highlight },
LspReferenceRead = { fg = p.rose, bg = p.highlight },
LspReferenceWrite = { fg = p.rose, bg = p.highlight },
} }
return syntax function theme.load_terminal()
end
theme.loadEditor = function()
local editor = {
ColorColumn = { bg = p.highlight_overlay },
-- Conceal = {},
-- Cursor = {},
CursorColumn = { bg = p.highlight },
-- CursorIM = {},
CursorLine = { bg = p.highlight_inactive },
CursorLineNr = { fg = p.text },
DarkenedPanel = { bg = p.surface },
DarkenedStatusline = { bg = p.surface },
DiffAdd = { fg = p.foam },
DiffChange = { fg = p.rose },
DiffDelete = { fg = p.love },
DiffText = { fg = p.text },
Directory = { fg = p.foam, bg = p.none },
-- EndOfBuffer = {},
ErrorMsg = { fg = p.love, style = 'bold' },
FloatBorder = { fg = p.highlight, bg = p.surface },
FoldColumn = {},
Folded = { fg = p.text, bg = p.surface },
IncSearch = { bg = p.highlight },
LineNr = { fg = p.inactive },
MatchParen = { fg = p.text, bg = p.overlay },
-- ModeMsg = {},
MoreMsg = { fg = p.iris },
NonText = { fg = p.inactive },
Normal = { fg = p.text },
-- NormalFloat = {},
Pmenu = { fg = p.subtle, bg = p.surface },
PmenuSbar = { bg = p.overlay },
PmenuSel = { fg = p.text, bg = p.overlay },
PmenuThumb = { bg = p.inactive },
Question = { fg = p.gold },
-- QuickFixLine = {},
Search = { fg = p.iris, bg = p.highlight_overlay },
SpecialKey = { fg = p.foam },
SpellBad = { style = 'undercurl', sp = p.love },
SpellCap = { style = 'undercurl', sp = p.subtle },
SpellLocal = { style = 'undercurl', sp = p.subtle },
SpellRare = { style = 'undercurl', sp = p.subtle },
SignColumn = {},
StatusLine = { fg = p.text, bg = p.surface },
StatusLineNC = { fg = p.subtle, bg = p.surface },
-- StatusLineTerm = {},
-- StatusLineTermNC = {},
-- TabLine = {},
-- TabLineFill = {},
-- TabLineSel = {},
Title = { fg = p.rose },
VertSplit = { fg = p.overlay },
Visual = { bg = p.highlight },
-- VisualNOS = {},
WarningMsg = { fg = p.gold },
-- Whitespace = {},
-- WildMenu = {},
}
if vim.g.rose_pine_disable_background == true then
editor.Normal = { fg = p.text, bg = p.none }
editor.SignColumn = { fg = p.text, bg = p.none }
else
editor.Normal = { fg = p.text, bg = p.base }
editor.SignColumn = { fg = p.text, bg = p.base }
end
return editor
end
theme.loadTerminal = function()
-- black -- black
vim.g.terminal_color_0 = p.overlay vim.g.terminal_color_0 = p.overlay
vim.g.terminal_color_8 = p.subtle vim.g.terminal_color_8 = p.subtle
@ -152,8 +166,7 @@ theme.loadTerminal = function()
vim.g.terminal_color_15 = p.text vim.g.terminal_color_15 = p.text
end end
theme.loadTreesitter = function() theme.treesitter = {
local treesitter = {
-- TSAnnotation = {}, -- TSAnnotation = {},
-- TSAttribute = {}, -- TSAttribute = {},
TSBoolean = { fg = p.rose }, TSBoolean = { fg = p.rose },
@ -219,41 +232,7 @@ theme.loadTreesitter = function()
TSVariableBuiltin = { fg = p.love }, TSVariableBuiltin = { fg = p.love },
} }
return treesitter theme.plugins = {
end
theme.loadLsp = function()
local lsp = {
LspDiagnosticsDefaultError = { fg = p.love },
LspDiagnosticsDefaultHint = { fg = p.iris },
LspDiagnosticsDefaultInformation = { fg = p.foam },
LspDiagnosticsDefaultWarning = { fg = p.gold },
LspDiagnosticsFloatingError = { fg = p.love },
LspDiagnosticsFloatingHint = { fg = p.iris },
LspDiagnosticsFloatingInformation = { fg = p.foam },
LspDiagnosticsFloatingWarning = { fg = p.gold },
LspDiagnosticsSignError = { fg = p.love },
LspDiagnosticsSignHint = { fg = p.iris },
LspDiagnosticsSignInformation = { fg = p.foam },
LspDiagnosticsSignWarning = { fg = p.gold },
LspDiagnosticsUnderlineError = { style = 'undercurl', sp = p.love },
LspDiagnosticsUnderlineHint = { style = 'undercurl', sp = p.iris },
LspDiagnosticsUnderlineInformation = { style = 'undercurl', sp = p.foam },
LspDiagnosticsUnderlineWarning = { style = 'undercurl', sp = p.gold },
LspDiagnosticsVirtualTextError = { fg = p.love },
LspDiagnosticsVirtualTextHint = { fg = p.iris },
LspDiagnosticsVirtualTextInformation = { fg = p.foam },
LspDiagnosticsVirtualTextWarning = { fg = p.gold },
LspReferenceRead = { fg = p.rose, bg = p.highlight },
LspReferenceText = { fg = p.rose, bg = p.highlight },
LspReferenceWrite = { fg = p.rose, bg = p.highlight },
}
return lsp
end
theme.loadPlugins = function()
local plugins = {
-- barbar.nvim -- barbar.nvim
-- https://github.com/romgrk/barbar.nvim -- https://github.com/romgrk/barbar.nvim
BufferTabpageFill = { bg = p.none }, BufferTabpageFill = { bg = p.none },
@ -313,14 +292,6 @@ theme.loadPlugins = function()
NvimTreeGitRenamed = { fg = p.pine }, NvimTreeGitRenamed = { fg = p.pine },
NvimTreeGitStaged = { fg = p.iris }, NvimTreeGitStaged = { fg = p.iris },
-- which-key.nvim
-- https://github.com/folke/which-key.nvim
WhichKey = { fg = p.iris },
WhichKeyGroup = { fg = p.foam },
WhichKeySeparator = { fg = p.subtle },
WhichKeyDesc = { fg = p.gold },
WhichKeyFloat = { bg = p.surface },
WhichKeyValue = { fg = p.rose },
-- todo-comments.nvim -- todo-comments.nvim
-- https://github.com/folke/todo-comments.nvim -- https://github.com/folke/todo-comments.nvim
@ -347,9 +318,15 @@ theme.loadPlugins = function()
TodoBgNOTE = { fg = '#000000', bg = p.iris }, TodoBgNOTE = { fg = '#000000', bg = p.iris },
TodoFgNOTE = { fg = p.iris, bg = p.base }, TodoFgNOTE = { fg = p.iris, bg = p.base },
TodoSignNOTE = { fg = p.iris, bg = p.base }, TodoSignNOTE = { fg = p.iris, bg = p.base },
-- which-key.nvim
-- https://github.com/folke/which-key.nvim
WhichKey = { fg = p.iris },
WhichKeyGroup = { fg = p.foam },
WhichKeySeparator = { fg = p.subtle },
WhichKeyDesc = { fg = p.gold },
WhichKeyFloat = { bg = p.surface },
WhichKeyValue = { fg = p.rose },
} }
return plugins
end
return theme return theme

View file

@ -1,5 +1,4 @@
local util = {} local util = {}
local theme = require('rose-pine.theme')
util.highlight = function(group, color) util.highlight = function(group, color)
local style = color.style and 'gui=' .. color.style or 'gui=NONE' local style = color.style and 'gui=' .. color.style or 'gui=NONE'
@ -25,11 +24,13 @@ util.highlight = function(group, color)
end end
function util.load() function util.load()
if vim.g.colors_name then
vim.cmd('hi clear') vim.cmd('hi clear')
if vim.fn.exists('syntax_on') then
vim.cmd('syntax reset')
end end
if
vim.o.termguicolors = true
vim.g.colors_name = 'rose-pine'
vim.g.rose_pine_variant == 'dawn' vim.g.rose_pine_variant == 'dawn'
or vim.g.rose_pine_variant == 'rose-pine-dawn' or vim.g.rose_pine_variant == 'rose-pine-dawn'
then then
@ -37,25 +38,18 @@ function util.load()
else else
vim.opt.background = 'dark' vim.opt.background = 'dark'
end end
vim.o.termguicolors = true
vim.g.colors_name = 'rose-pine' local theme = require('rose-pine.theme')
local async local async
async = vim.loop.new_async(vim.schedule_wrap(function() async = vim.loop.new_async(vim.schedule_wrap(function()
theme.loadTerminal() theme.load_terminal()
local plugins = theme.loadPlugins()
local treesitter = theme.loadTreesitter()
local lsp = theme.loadLsp()
for group, colors in pairs(plugins) do for group, colors in pairs(theme.treesitter) do
util.highlight(group, colors) util.highlight(group, colors)
end end
for group, colors in pairs(treesitter) do for group, colors in pairs(theme.plugins) do
util.highlight(group, colors)
end
for group, colors in pairs(lsp) do
util.highlight(group, colors) util.highlight(group, colors)
end end
@ -63,18 +57,11 @@ function util.load()
end)) end))
-- load priority groups first -- load priority groups first
local editor = theme.loadEditor() for group, colors in pairs(theme.base) do
local syntax = theme.loadSyntax()
for group, colors in pairs(editor) do
util.highlight(group, colors) util.highlight(group, colors)
end end
for group, colors in pairs(syntax) do -- load enhancements (eg. treesitter, plugins)
util.highlight(group, colors)
end
-- load enhancements (eg. lsp, treesitter, plugins)
async:send() async:send()
end end