refactor: refactored code to better deal with the day theme
This commit is contained in:
parent
3c05c5ad8e
commit
dba4e35903
@ -1,5 +1,4 @@
|
|||||||
local config = require("tokyonight.config")
|
local colors = require("tokyonight.colors").setup({ transform = true })
|
||||||
local colors = require("tokyonight.colors").setup(config)
|
|
||||||
|
|
||||||
local tokyonight = {}
|
local tokyonight = {}
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
local config = require("tokyonight.config")
|
local colors = require("tokyonight.colors").setup({ transform = true })
|
||||||
local colors = require("tokyonight.colors").setup(config)
|
|
||||||
local util = require("tokyonight.util")
|
|
||||||
|
|
||||||
local tokyonight = {}
|
local tokyonight = {}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
local util = require("tokyonight.util")
|
local util = require("tokyonight.util")
|
||||||
|
local config = require("tokyonight.config").options
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@param config Config
|
|
||||||
---@return ColorScheme
|
---@return ColorScheme
|
||||||
function M.setup(config)
|
function M.setup(opts)
|
||||||
config = config or require("tokyonight.config")
|
opts = opts or {}
|
||||||
|
|
||||||
-- Color Palette
|
-- Color Palette
|
||||||
---@class ColorScheme
|
---@class ColorScheme
|
||||||
@ -40,7 +40,7 @@ function M.setup(config)
|
|||||||
teal = "#1abc9c",
|
teal = "#1abc9c",
|
||||||
red = "#f7768e",
|
red = "#f7768e",
|
||||||
red1 = "#db4b4b",
|
red1 = "#db4b4b",
|
||||||
git = { change = "#6183bb", add = "#449dab", delete = "#914c54", conflict = "#bb7a61" },
|
git = { change = "#6183bb", add = "#449dab", delete = "#914c54" },
|
||||||
}
|
}
|
||||||
if config.style == "night" or config.style == "day" or vim.o.background == "light" then
|
if config.style == "night" or config.style == "day" or vim.o.background == "light" then
|
||||||
colors.bg = "#1a1b26"
|
colors.bg = "#1a1b26"
|
||||||
@ -86,8 +86,8 @@ function M.setup(config)
|
|||||||
|
|
||||||
util.color_overrides(colors, config)
|
util.color_overrides(colors, config)
|
||||||
|
|
||||||
if config.style == "day" or vim.o.background == "light" then
|
if opts.transform and (config.style == "day" or vim.o.background == "light") then
|
||||||
return util.invert_colors(colors)
|
util.invert_colors(colors)
|
||||||
end
|
end
|
||||||
|
|
||||||
return colors
|
return colors
|
||||||
|
@ -1,40 +1,37 @@
|
|||||||
-- shim vim for kitty and other generators
|
-- shim vim for kitty and other generators
|
||||||
vim = vim or { g = {}, o = {} }
|
vim = vim or { g = {}, o = {} }
|
||||||
|
|
||||||
local function opt(key, default)
|
local M = {}
|
||||||
key = "tokyonight_" .. key
|
|
||||||
if vim.g[key] == nil then
|
|
||||||
return default
|
|
||||||
end
|
|
||||||
if vim.g[key] == 0 then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return vim.g[key]
|
|
||||||
end
|
|
||||||
|
|
||||||
---@class Config
|
---@class Config
|
||||||
local config = {
|
local defaults = {
|
||||||
style = opt("style", "storm"),
|
style = "storm",
|
||||||
dayBrightness = opt("day_brightness", 0.3),
|
styles = {
|
||||||
transparent = opt("transparent", false),
|
comments = "italic",
|
||||||
commentStyle = opt("italic_comments", true) and "italic" or "NONE",
|
functions = "NONE",
|
||||||
keywordStyle = opt("italic_keywords", true) and "italic" or "NONE",
|
keywords = "italic",
|
||||||
functionStyle = opt("italic_functions", false) and "italic" or "NONE",
|
variables = "NONE",
|
||||||
variableStyle = opt("italic_variables", false) and "italic" or "NONE",
|
},
|
||||||
hideInactiveStatusline = opt("hide_inactive_statusline", false),
|
colors = {},
|
||||||
terminalColors = opt("terminal_colors", true),
|
darkFloat = true,
|
||||||
sidebars = opt("sidebars", {}),
|
darkSidebar = true,
|
||||||
colors = opt("colors", {}),
|
dayBrightness = 0.3,
|
||||||
dev = opt("dev", false),
|
dev = false,
|
||||||
darkFloat = opt("dark_float", true),
|
hideInactiveStatusline = false,
|
||||||
darkSidebar = opt("dark_sidebar", true),
|
lualineBold = false,
|
||||||
transparentSidebar = opt("transparent_sidebar", false),
|
sidebars = {},
|
||||||
transform_colors = false,
|
terminalColors = true,
|
||||||
lualineBold = opt("lualine_bold", false),
|
transparent = false,
|
||||||
|
transparentSidebar = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.style == "day" then
|
---@type Config
|
||||||
vim.o.background = "light"
|
M.options = {}
|
||||||
|
|
||||||
|
function M.setup(options)
|
||||||
|
M.options = vim.tbl_deep_extend("force", {}, defaults, options or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
return config
|
M.setup()
|
||||||
|
|
||||||
|
return M
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package.path = "./lua/?/init.lua;./lua/?.lua"
|
package.path = "./lua/?/init.lua;./lua/?.lua"
|
||||||
|
|
||||||
local config = require("tokyonight.config")
|
local config = require("tokyonight.config").options
|
||||||
|
|
||||||
local function write(str, fileName)
|
local function write(str, fileName)
|
||||||
print("[write] extra/" .. fileName)
|
print("[write] extra/" .. fileName)
|
||||||
@ -32,8 +32,7 @@ for extra, ext in pairs(extras) do
|
|||||||
local plugin = require("tokyonight.extra." .. extra)
|
local plugin = require("tokyonight.extra." .. extra)
|
||||||
for style, style_name in pairs(styles) do
|
for style, style_name in pairs(styles) do
|
||||||
config.style = style
|
config.style = style
|
||||||
config = config or require("tokyonight.config")
|
local colors = require("tokyonight.colors").setup({ transform = true })
|
||||||
local colors = require("tokyonight.colors").setup(config)
|
|
||||||
local fname = extra .. "_tokyonight_" .. style .. "." .. ext
|
local fname = extra .. "_tokyonight_" .. style .. "." .. ext
|
||||||
colors["_upstream_url"] = "https://github.com/folke/tokyonight.nvim/raw/main/extras/" .. fname
|
colors["_upstream_url"] = "https://github.com/folke/tokyonight.nvim/raw/main/extras/" .. fname
|
||||||
colors["_style_name"] = "Tokyo Night" .. style_name
|
colors["_style_name"] = "Tokyo Night" .. style_name
|
||||||
|
@ -1,22 +1,31 @@
|
|||||||
local util = require("tokyonight.util")
|
local util = require("tokyonight.util")
|
||||||
local colors = require("tokyonight.colors")
|
local colors = require("tokyonight.colors")
|
||||||
|
local config = require("tokyonight.config").options
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
--
|
||||||
|
---@class Highlight
|
||||||
|
---@field fg string|nil
|
||||||
|
---@field bg string|nil
|
||||||
|
---@field sp string|nil
|
||||||
|
---@field style string|nil
|
||||||
|
|
||||||
|
---@alias Highlights table<string,Highlight>
|
||||||
|
|
||||||
---@param config Config
|
|
||||||
---@return Theme
|
---@return Theme
|
||||||
function M.setup(config)
|
function M.setup()
|
||||||
config = config or require("tokyonight.config")
|
|
||||||
|
|
||||||
---@class Theme
|
---@class Theme
|
||||||
local theme = {}
|
---@field base Highlights
|
||||||
theme.config = config
|
---@field plugins Highlights
|
||||||
theme.colors = colors.setup(config)
|
local theme = {
|
||||||
|
config = config,
|
||||||
|
colors = colors.setup(),
|
||||||
|
}
|
||||||
|
|
||||||
local c = theme.colors
|
local c = theme.colors
|
||||||
|
|
||||||
theme.base = {
|
theme.base = {
|
||||||
Comment = { fg = c.comment, style = config.commentStyle }, -- any comment
|
Comment = { fg = c.comment, style = config.styles.comments }, -- any comment
|
||||||
ColorColumn = { bg = c.black }, -- used for the columns set with 'colorcolumn'
|
ColorColumn = { bg = c.black }, -- used for the columns set with 'colorcolumn'
|
||||||
Conceal = { fg = c.dark5 }, -- placeholder characters substituted for concealed text (see 'conceallevel')
|
Conceal = { fg = c.dark5 }, -- placeholder characters substituted for concealed text (see 'conceallevel')
|
||||||
Cursor = { fg = c.bg, bg = c.fg }, -- character under the cursor
|
Cursor = { fg = c.bg, bg = c.fg }, -- character under the cursor
|
||||||
@ -90,15 +99,15 @@ function M.setup(config)
|
|||||||
-- Boolean = { }, -- a boolean constant: TRUE, false
|
-- Boolean = { }, -- a boolean constant: TRUE, false
|
||||||
-- Float = { }, -- a floating point constant: 2.3e10
|
-- Float = { }, -- a floating point constant: 2.3e10
|
||||||
|
|
||||||
Identifier = { fg = c.magenta, style = config.variableStyle }, -- (preferred) any variable name
|
Identifier = { fg = c.magenta, style = config.styles.variables }, -- (preferred) any variable name
|
||||||
Function = { fg = c.blue, style = config.functionStyle }, -- function name (also: methods for classes)
|
Function = { fg = c.blue, style = config.styles.functions }, -- function name (also: methods for classes)
|
||||||
|
|
||||||
Statement = { fg = c.magenta }, -- (preferred) any statement
|
Statement = { fg = c.magenta }, -- (preferred) any statement
|
||||||
-- Conditional = { }, -- if, then, else, endif, switch, etc.
|
-- Conditional = { }, -- if, then, else, endif, switch, etc.
|
||||||
-- Repeat = { }, -- for, do, while, etc.
|
-- Repeat = { }, -- for, do, while, etc.
|
||||||
-- Label = { }, -- case, default, etc.
|
-- Label = { }, -- case, default, etc.
|
||||||
Operator = { fg = c.blue5 }, -- "sizeof", "+", "*", etc.
|
Operator = { fg = c.blue5 }, -- "sizeof", "+", "*", etc.
|
||||||
Keyword = { fg = c.cyan, style = config.keywordStyle }, -- any other keyword
|
Keyword = { fg = c.cyan, style = config.styles.keywords }, -- any other keyword
|
||||||
-- Exception = { }, -- try, catch, throw
|
-- Exception = { }, -- try, catch, throw
|
||||||
|
|
||||||
PreProc = { fg = c.cyan }, -- (preferred) generic Preprocessor
|
PreProc = { fg = c.cyan }, -- (preferred) generic Preprocessor
|
||||||
@ -227,8 +236,8 @@ function M.setup(config)
|
|||||||
-- TSFuncBuiltin = { }; -- For builtin functions: `table.insert` in Lua.
|
-- TSFuncBuiltin = { }; -- For builtin functions: `table.insert` in Lua.
|
||||||
-- TSFuncMacro = { }; -- For macro defined fuctions (calls and definitions): each `macro_rules` in Rust.
|
-- TSFuncMacro = { }; -- For macro defined fuctions (calls and definitions): each `macro_rules` in Rust.
|
||||||
-- TSInclude = { }; -- For includes: `#include` in C, `use` or `extern crate` in Rust, or `require` in Lua.
|
-- TSInclude = { }; -- For includes: `#include` in C, `use` or `extern crate` in Rust, or `require` in Lua.
|
||||||
TSKeyword = { fg = c.purple, style = config.keywordStyle }, -- For keywords that don't fall in previous categories.
|
TSKeyword = { fg = c.purple, style = config.styles.keywords }, -- For keywords that don't fall in previous categories.
|
||||||
TSKeywordFunction = { fg = c.magenta, style = config.functionStyle }, -- For keywords used to define a fuction.
|
TSKeywordFunction = { fg = c.magenta, style = config.styles.functions }, -- For keywords used to define a fuction.
|
||||||
TSLabel = { fg = c.blue }, -- For labels: `label:` in C and `:label:` in Lua.
|
TSLabel = { fg = c.blue }, -- For labels: `label:` in C and `:label:` in Lua.
|
||||||
-- TSMethod = { }; -- For method calls and definitions.
|
-- TSMethod = { }; -- For method calls and definitions.
|
||||||
-- TSNamespace = { }; -- For identifiers referring to modules and namespaces.
|
-- TSNamespace = { }; -- For identifiers referring to modules and namespaces.
|
||||||
@ -248,7 +257,7 @@ function M.setup(config)
|
|||||||
-- TSSymbol = { }; -- For identifiers referring to symbols or atoms.
|
-- TSSymbol = { }; -- For identifiers referring to symbols or atoms.
|
||||||
-- TSType = { }; -- For types.
|
-- TSType = { }; -- For types.
|
||||||
-- TSTypeBuiltin = { }; -- For builtin types.
|
-- TSTypeBuiltin = { }; -- For builtin types.
|
||||||
TSVariable = { style = config.variableStyle }, -- Any variable name that does not have another highlight.
|
TSVariable = { style = config.styles.variables }, -- Any variable name that does not have another highlight.
|
||||||
TSVariableBuiltin = { fg = c.red }, -- Variable names that are defined by the languages, like `this` or `self`.
|
TSVariableBuiltin = { fg = c.red }, -- Variable names that are defined by the languages, like `this` or `self`.
|
||||||
|
|
||||||
-- TSTag = { }; -- Tags like html tag names.
|
-- TSTag = { }; -- Tags like html tag names.
|
||||||
@ -510,7 +519,7 @@ function M.setup(config)
|
|||||||
MiniStarterCurrent = { style = "nocombine" },
|
MiniStarterCurrent = { style = "nocombine" },
|
||||||
MiniStarterFooter = { fg = c.yellow, style = "italic" },
|
MiniStarterFooter = { fg = c.yellow, style = "italic" },
|
||||||
MiniStarterHeader = { fg = c.blue },
|
MiniStarterHeader = { fg = c.blue },
|
||||||
MiniStarterInactive = { fg = c.comment, style = config.commentStyle },
|
MiniStarterInactive = { fg = c.comment, style = config.styles.comments },
|
||||||
MiniStarterItem = { fg = c.fg, bg = config.transparent and c.none or c.bg },
|
MiniStarterItem = { fg = c.fg, bg = config.transparent and c.none or c.bg },
|
||||||
MiniStarterItemBullet = { fg = c.border_highlight },
|
MiniStarterItemBullet = { fg = c.border_highlight },
|
||||||
MiniStarterItemPrefix = { fg = c.warning },
|
MiniStarterItemPrefix = { fg = c.warning },
|
||||||
@ -563,6 +572,12 @@ function M.setup(config)
|
|||||||
theme.plugins.MiniStatuslineInactive = inactive
|
theme.plugins.MiniStatuslineInactive = inactive
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if config.style == "day" or vim.o.background == "light" then
|
||||||
|
util.invert_colors(theme.colors)
|
||||||
|
util.invert_highlights(theme.base)
|
||||||
|
util.invert_highlights(theme.plugins)
|
||||||
|
end
|
||||||
|
|
||||||
return theme
|
return theme
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -184,17 +184,29 @@ function util.terminal(colors)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param colors ColorScheme
|
---@param colors ColorScheme
|
||||||
---@return ColorScheme
|
|
||||||
function util.invert_colors(colors)
|
function util.invert_colors(colors)
|
||||||
if type(colors) == "string" then
|
if type(colors) == "string" then
|
||||||
---@diagnostic disable-next-line: return-type-mismatch
|
---@diagnostic disable-next-line: return-type-mismatch
|
||||||
return util.invert_color(colors)
|
return util.invert_color(colors)
|
||||||
end
|
end
|
||||||
local ret = {}
|
|
||||||
for key, value in pairs(colors) do
|
for key, value in pairs(colors) do
|
||||||
ret[key] = util.invert_colors(value)
|
colors[key] = util.invert_colors(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param hls Highlights
|
||||||
|
function util.invert_highlights(hls)
|
||||||
|
for _, hl in pairs(hls) do
|
||||||
|
if hl.fg then
|
||||||
|
hl.fg = util.invert_color(hl.fg)
|
||||||
|
end
|
||||||
|
if hl.bg then
|
||||||
|
hl.bg = util.invert_color(hl.bg)
|
||||||
|
end
|
||||||
|
if hl.sp then
|
||||||
|
hl.sp = util.invert_color(hl.sp)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param theme Theme
|
---@param theme Theme
|
||||||
@ -203,9 +215,6 @@ function util.load(theme)
|
|||||||
if vim.g.colors_name then
|
if vim.g.colors_name then
|
||||||
vim.cmd("hi clear")
|
vim.cmd("hi clear")
|
||||||
end
|
end
|
||||||
-- if vim.fn.exists("syntax_on") then
|
|
||||||
-- vim.cmd("syntax reset")
|
|
||||||
-- end
|
|
||||||
|
|
||||||
vim.o.termguicolors = true
|
vim.o.termguicolors = true
|
||||||
vim.g.colors_name = "tokyonight"
|
vim.g.colors_name = "tokyonight"
|
||||||
|
Loading…
Reference in New Issue
Block a user