Skip to content

Commit

Permalink
feat(theme): add theme switching
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimonho committed Feb 15, 2025
1 parent 9f3969f commit 2220c56
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 177 deletions.
1 change: 1 addition & 0 deletions colors/kanagawa-paper-canvas.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("kanagawa-paper").load({ theme = "canvas" })
1 change: 1 addition & 0 deletions colors/kanagawa-paper-ink.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("kanagawa-paper").load({ theme = "ink" })
1 change: 1 addition & 0 deletions colors/kanagawa-paper.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("kanagawa-paper").load()
1 change: 0 additions & 1 deletion colors/kanagawa-paper.vim

This file was deleted.

9 changes: 5 additions & 4 deletions lua/kanagawa-paper/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ local palette = {
local M = {}
--- Generate colors table:
--- * opts:
--- - theme: string, one of "ink", "canvas"
--- - colors: Table of personalized colors and/or overrides of existing ones.
--- Defaults to KanagawaConfig.colors.
---@param opts? { colors?: table }
---@param opts? {theme: string, colors?: table }
---@return { theme: ThemeColors, palette: PaletteColors}
function M.setup(opts)
opts = opts or {}
Expand All @@ -143,12 +144,12 @@ function M.setup(opts)
local updated_palette_colors = vim.tbl_extend("force", palette, override_colors.palette or {})

-- Generate the theme according to the updated palette colors
local theme_colors = require("kanagawa-paper.themes")(updated_palette_colors)
local theme_colors = require("kanagawa-paper.themes")[opts.theme](updated_palette_colors)

-- Add to and/or override theme_colors
local updated_theme_colors = vim.tbl_deep_extend("force", theme_colors, override_colors.theme or {})
local updated_theme_colors = vim.tbl_deep_extend("force", theme_colors, override_colors.theme[opts.theme] or {})

-- return palette_colors AND theme_colors
-- return palette_colors and theme_colors
return {
theme = updated_theme_colors,
palette = updated_palette_colors,
Expand Down
11 changes: 8 additions & 3 deletions lua/kanagawa-paper/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local M = {}

---@class KanagawaConfig
local defaults = {
theme = "ink",
undercurl = true,
transparent = false,
gutter = false,
Expand All @@ -22,14 +23,18 @@ local defaults = {
overrides = function()
return {}
end,
all_plugins = false,
all_plugins = true, -- enable highlights for all the plugins
plugins = {
grug_far = true,
-- manually enable/disable individual plugins
-- check the groups/plugins directory for the exact names
-- examples:
-- rainbow_delimiters = true
-- which_key = false
},
}

---@type KanagawaConfig
M.options = {}
M.options = nil

---@param options? KanagawaConfig user configuration
function M.setup(options)
Expand Down
17 changes: 13 additions & 4 deletions lua/kanagawa-paper/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ function M.load(opts)
if opts then
config.extend(opts)
end

-- only needed to clear when not the default colorscheme
if vim.g.colors_name then
vim.cmd("hi clear")
end

vim.g.colors_name = "kanagawa-paper"
vim.o.termguicolors = true
vim.g.colors_name = "kanagawa-paper-" .. config.options.theme
if config.options.theme == "ink" then
vim.o.background = "dark"
elseif config.options.theme == "canvas" then
vim.o.background = "light"
else
vim.notify("Invalid theme: " .. config.options.theme, vim.log.levels.ERROR)
end

local colors = require("kanagawa-paper.colors").setup({ colors = config.options.colors })
local colors = require("kanagawa-paper.colors").setup(config.options)
local groups = require("kanagawa-paper.groups.init").setup(colors, config.options)
require("kanagawa-paper.groups.init").highlight(groups, config.terminalColors and colors.theme.term or {})

-- create terminal highlights
require("kanagawa-paper.groups.init").highlight(groups, config.options.terminalColors and colors.theme.term or {})
end

M.setup = config.setup
Expand Down
Loading

0 comments on commit 2220c56

Please # to comment.