Skip to content

Commit

Permalink
feat: added colorschemes default configs checks and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed May 6, 2024
1 parent a23b40e commit 4c61267
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 5 deletions.
24 changes: 24 additions & 0 deletions lua/colorscheme-installer/colorschemes/configs/kanagawa.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
return {
compile = false, -- enable compiling the colorscheme
undercurl = true, -- enable undercurls
commentStyle = { italic = true },
functionStyle = {},
keywordStyle = { italic = true },
statementStyle = { bold = true },
typeStyle = {},
transparent = false, -- do not set background color
dimInactive = false, -- dim inactive window `:h hl-NormalNC`
terminalColors = true, -- define vim.g.terminal_color_{0,17}
colors = { -- add/modify theme and palette colors
palette = {},
theme = { wave = {}, lotus = {}, dragon = {}, all = {} },
},
overrides = function(colors) -- add/modify highlights
return {}
end,
theme = "wave", -- Load "wave" theme when 'background' option is not set
background = { -- map the value of 'background' option to a theme
dark = "wave", -- try "dragon" !
light = "lotus",
},
}
37 changes: 37 additions & 0 deletions lua/colorscheme-installer/colorschemes/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local M = {}

---Require the colorscheme config
---@param colorscheme string
---@return table
local function get_default_config(colorscheme)
local config = require("colorscheme-installer.colorschemes.configs." .. colorscheme)
return config
end

---Check if colorscheme is installed
---@param colorscheme string
---@return boolean
local function is_installed(colorscheme)
if vim.g["cs_" .. colorscheme .. "_installed"] then
return vim.g["cs_" .. colorscheme .. "_installed"]
end
local colors = vim.fn.getcompletion("", "color")
for _, color in ipairs(colors) do
if colorscheme == color then
vim.g["cs_" .. colorscheme .. "_installed"] = true
return true
end
end
return false
end

M.colorschemes = {
{
repo = "rebelot/kanagawa.nvim",
name = "kanagawa",
default_config = get_default_config("kanagawa"),
installed = is_installed("kanagawa"),
},
}

return M
12 changes: 7 additions & 5 deletions lua/colorscheme-installer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local logger = require("colorscheme-installer.utils.logger")

---@class ColorschemeInstaller
---@field config ColorschemeConfig
---@field _cs_configs table
local cs_installer = {} -- colorscheme_installer

---@class ColorschemeConfig
Expand All @@ -10,19 +11,20 @@ local config = {
colorschemes_path = os.getenv("HOME") .. "/.config/nvim/lua/colorschemes",
}

-- default configs
-- default config
cs_installer.config = config

-- defautl colorschemes configs
cs_installer._cs_configs = require("colorscheme-installer.colorschemes").colorschemes

---Colorscheme installer set up function
---@param opts ColorschemeConfig|nil
cs_installer.setup = function(opts)
cs_installer.config = vim.tbl_extend("force", {}, cs_installer.config, opts or {})
if vim.version().minor < 8 then
logger.err_once("colorscheme-installer.nvim: you must use neovim 0.8 or higher")
if vim.version().minor < 9 then
logger.err_once("colorscheme-installer.nvim: you must use neovim 0.9.0 or higher")
return
end
logger.info("colorscheme-installer.nvim has been setted up")
logger.info(string.format("setting up colorschemes in: %s", cs_installer.config.colorschemes_path))
end

return cs_installer
32 changes: 32 additions & 0 deletions tests/colorscheme-installer/cs_installer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ local csi = require("colorscheme-installer")

local eq = assert.are.same

---Require the colorscheme config
---@param colorscheme string
---@return table
local function get_default_config(colorscheme)
local config = require("colorscheme-installer.colorschemes.configs." .. colorscheme)
return config
end

describe("setup", function()
it("setup with default configs", function()
local expected = {
Expand All @@ -22,3 +30,27 @@ describe("setup", function()
eq(csi.config, expected)
end)
end)

describe("colorschemes", function()
it("has colorschemes configs", function()
assert.are_not.same(csi._cs_configs, nil)
end)

it("has colorscheme config for `kanagawa`", function()
local expected = get_default_config("kanagawa")

for _, config in ipairs(csi._cs_configs) do
if config.name == "kanagawa" then
eq(config.default_config, expected)
end
end
end)

it("has `kanagawa` uninstalled", function()
for _, config in ipairs(csi._cs_configs) do
if config.name == "kanagawa" then
eq(config.installed, false)
end
end
end)
end)

0 comments on commit 4c61267

Please sign in to comment.