From 6bdbe52159e2a2fc21c830a3ac8bd25c4cd42085 Mon Sep 17 00:00:00 2001 From: mvllow Date: Fri, 3 Dec 2021 09:30:47 -0600 Subject: [PATCH] refactor: simplify init --- colors/rose-pine.vim | 13 ++++----- lua/rose-pine/init.lua | 49 +++++++++++++++++++++++++++++--- lua/rose-pine/util.lua | 63 ------------------------------------------ 3 files changed, 50 insertions(+), 75 deletions(-) delete mode 100644 lua/rose-pine/util.lua diff --git a/colors/rose-pine.vim b/colors/rose-pine.vim index 4b06354..af1ddba 100644 --- a/colors/rose-pine.vim +++ b/colors/rose-pine.vim @@ -1,9 +1,6 @@ -lua << EOF -package.loaded['rose-pine'] = nil -package.loaded['rose-pine.functions'] = nil -package.loaded['rose-pine.palette'] = nil -package.loaded['rose-pine.theme'] = nil -package.loaded['rose-pine.util'] = nil +lua package.loaded['rose-pine'] = nil +lua package.loaded['rose-pine.config'] = nil +lua package.loaded['rose-pine.palette'] = nil +lua package.loaded['rose-pine.theme'] = nil -require('rose-pine').set() -EOF +lua require('rose-pine').colorscheme() diff --git a/lua/rose-pine/init.lua b/lua/rose-pine/init.lua index 10a37b0..99d59c5 100644 --- a/lua/rose-pine/init.lua +++ b/lua/rose-pine/init.lua @@ -1,9 +1,50 @@ -local util = require('rose-pine.util') - local M = {} -function M.set() - util.load() +function M.colorscheme() + if vim.g.colors_name then + vim.cmd('hi clear') + end + + vim.opt.termguicolors = true + vim.g.colors_name = 'rose-pine' + + -- Match terminal theme if no variant is set + if vim.g.rose_pine_variant == nil and vim.o.background == 'light' then + vim.g.rose_pine_variant = 'dawn' + elseif vim.g.rose_pine_variant == 'dawn' then + vim.o.background = 'light' + end + + ---@param group string + ---@param color table + local function highlight(group, color) + local style = color.style and 'gui=' .. color.style or 'gui=NONE' + local fg = color.fg and 'guifg=' .. color.fg or 'guifg=NONE' + local bg = color.bg and 'guibg=' .. color.bg or 'guibg=NONE' + local sp = color.sp and 'guisp=' .. color.sp or '' + + local hl = 'highlight ' + .. group + .. ' ' + .. style + .. ' ' + .. fg + .. ' ' + .. bg + .. ' ' + .. sp + + vim.cmd(hl) + if color.link then + vim.cmd('highlight! link ' .. group .. ' ' .. color.link) + end + end + + for group, colors in pairs(require('rose-pine.theme')) do + highlight(group, colors) + end + + require('rose-pine.galaxyline.theme') end return M diff --git a/lua/rose-pine/util.lua b/lua/rose-pine/util.lua deleted file mode 100644 index ba7b117..0000000 --- a/lua/rose-pine/util.lua +++ /dev/null @@ -1,63 +0,0 @@ -local util = {} - -util.highlight = function(group, color) - local style = color.style and 'gui=' .. color.style or 'gui=NONE' - local fg = color.fg and 'guifg=' .. color.fg or 'guifg=NONE' - local bg = color.bg and 'guibg=' .. color.bg or 'guibg=NONE' - local sp = color.sp and 'guisp=' .. color.sp or '' - - local hl = 'highlight ' - .. group - .. ' ' - .. style - .. ' ' - .. fg - .. ' ' - .. bg - .. ' ' - .. sp - - vim.cmd(hl) - if color.link then - vim.cmd('highlight! link ' .. group .. ' ' .. color.link) - end -end - -function util.load() - if vim.g.colors_name then - vim.cmd('hi clear') - end - - vim.o.termguicolors = true - vim.g.colors_name = 'rose-pine' - - if vim.o.background == 'light' and vim.g.rose_pine_variant == nil then - vim.g.rose_pine_variant = 'dawn' - elseif - vim.g.rose_pine_variant == 'dawn' - or vim.g.rose_pine_variant == 'rose-pine-dawn' - then - vim.o.background = 'light' - end - - local theme = require('rose-pine.theme') - - theme.load_terminal() - - for group, colors in pairs(theme.base) do - util.highlight(group, colors) - end - - for group, colors in pairs(theme.treesitter) do - util.highlight(group, colors) - end - - for group, colors in pairs(theme.plugins) do - util.highlight(group, colors) - end - - -- Load galaxyline theme - require("rose-pine.galaxyline.theme") -end - -return util