Skip to content

Commit

Permalink
refactor: update the init of solarized
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmx03 committed Dec 8, 2023
1 parent fa3e740 commit d41104c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
4 changes: 1 addition & 3 deletions colors/solarized.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
lua << EOF
local solarized = require('solarized')

solarized.setup()
require('solarized').load()
EOF
47 changes: 23 additions & 24 deletions lua/solarized/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ local solarized_palette = require('solarized.palette')
local solarized_highlights = require('solarized.highlights')

local M = {}
M.is_configured = false
M.has_set_highlights = false
M.config = {}
M.config = nil
M.colors = nil

function M.load()
if vim.g.colors_name then
vim.cmd('hi clear')
end

if vim.fn.exists('syntax_on') then
vim.cmd('syntax reset')
end

vim.o.termguicolors = true
vim.g.colors_name = 'solarized'

local default_config = solarized_config()
local colors = solarized_palette.get_colors()
solarized_highlights(M.colors or colors, M.config or default_config)
end

--- Solarized setup
---
Expand All @@ -24,33 +40,16 @@ M.config = {}
--- - enables (table): A table specifying plugins to be enabled or disabled
--- - theme (string): Specifies the theme to be used.
function M.setup(opts)
if vim.g.colors_name then
vim.cmd('hi clear')
end

if vim.fn.exists('syntax_on') then
vim.cmd('syntax reset')
end

vim.o.termguicolors = true
vim.g.colors_name = 'solarized'

if not M.is_configured then
local default_config = solarized_config()
M.config = vim.tbl_deep_extend('force', default_config, opts or {})
M.is_configured = true
end

local default_config = solarized_config()
M.config = vim.tbl_deep_extend('force', default_config, opts or {})
local colors = solarized_palette.get_colors()

if type(M.config.colors) == 'table' and not vim.tbl_isempty(M.config.colors) then
colors = solarized_palette.extend_colors(colors, M.config.colors)
M.colors = solarized_palette.extend_colors(colors, M.config.colors)
elseif type(M.config.colors) == 'function' then
local colorhelper = require('solarized.utils.colors')
colors = solarized_palette.extend_colors(colors, M.config.colors(colors, colorhelper))
M.colors = solarized_palette.extend_colors(colors, M.config.colors(colors, colorhelper))
end

solarized_highlights(colors, M.config)
end

return M
9 changes: 3 additions & 6 deletions tests/setup_spec.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
describe('Solarized', function()
it('should setup without any errors', function()
vim.cmd.colorscheme('solarized')
vim.o.background = 'light'
vim.cmd.colorscheme('solarized')

it('should load without any errors', function()
assert.equal('solarized', vim.g.colors_name)
assert.is_true(vim.o.termguicolors)
end)
Expand All @@ -11,11 +12,7 @@ describe('Solarized', function()
return string.format('#%06x', decimal)
end

vim.o.background = 'light'

local output = vim.api.nvim_get_hl(0, { name = 'Normal' })
assert.equals('#fdf6e3', tohex(output.bg))

vim.cmd.colorscheme('solarized')
end)
end)

0 comments on commit d41104c

Please sign in to comment.