build: selene + stylua

This commit is contained in:
Folke Lemaitre
2021-05-12 11:19:28 +02:00
parent fc7301ab94
commit 09cc28432f
13 changed files with 269 additions and 155 deletions

View File

@@ -39,8 +39,12 @@ tokyonight.inactive = {
if vim.o.background == "light" then if vim.o.background == "light" then
for _, mode in pairs(tokyonight) do for _, mode in pairs(tokyonight) do
for _, section in pairs(mode) do for _, section in pairs(mode) do
if section.bg then section.bg = util.getColor(section.bg) end if section.bg then
if section.fg then section.fg = util.getColor(section.fg) end section.bg = util.getColor(section.bg)
end
if section.fg then
section.fg = util.getColor(section.fg)
end
end end
end end
end end

View File

@@ -49,16 +49,16 @@ function M.setup(config)
util.bg = colors.bg util.bg = colors.bg
colors.diff = { colors.diff = {
add = util.darken(colors.green2, .15), add = util.darken(colors.green2, 0.15),
delete = util.darken(colors.red1, .15), delete = util.darken(colors.red1, 0.15),
change = util.darken(colors.blue7, .15), change = util.darken(colors.blue7, 0.15),
text = colors.blue7, text = colors.blue7,
} }
colors.gitSigns = { colors.gitSigns = {
add = util.brighten(colors.diff.add, .2), add = util.brighten(colors.diff.add, 0.2),
change = util.brighten(colors.diff.change, .2), change = util.brighten(colors.diff.change, 0.2),
delete = util.brighten(colors.diff.delete, .2), delete = util.brighten(colors.diff.delete, 0.2),
} }
colors.git.ignore = colors.dark3 colors.git.ignore = colors.dark3
@@ -93,4 +93,3 @@ function M.setup(config)
end end
return M return M

View File

@@ -6,8 +6,12 @@ vim = vim or { g = {}, o = {} }
local function opt(key, default) local function opt(key, default)
key = "tokyonight_" .. key key = "tokyonight_" .. key
if vim.g[key] == nil then return default end if vim.g[key] == nil then
if vim.g[key] == 0 then return false end return default
end
if vim.g[key] == 0 then
return false
end
return vim.g[key] return vim.g[key]
end end
@@ -28,6 +32,8 @@ config = {
transform_colors = false, transform_colors = false,
} }
if config.style == "day" then vim.o.background = "light" end if config.style == "day" then
vim.o.background = "light"
end
return config return config

View File

@@ -9,10 +9,13 @@ function M.alacritty(config)
local alacrittyColors = {} local alacrittyColors = {}
for k, v in pairs(colors) do for k, v in pairs(colors) do
if type(v) == "string" then alacrittyColors[k] = v:gsub("^#", "0x") end if type(v) == "string" then
alacrittyColors[k] = v:gsub("^#", "0x")
end
end end
local alacritty = util.template([[ local alacritty = util.template(
[[
# TokyoNight Alacritty Colors # TokyoNight Alacritty Colors
colors: colors:
# Default colors # Default colors
@@ -46,10 +49,11 @@ colors:
- { index: 16, color: '${orange}' } - { index: 16, color: '${orange}' }
- { index: 17, color: '${red1}' } - { index: 17, color: '${red1}' }
]], alacrittyColors) ]],
alacrittyColors
)
return alacritty return alacritty
end end
return M return M

View File

@@ -8,9 +8,14 @@ function M.fish(config)
local colors = require("tokyonight.colors").setup(config) local colors = require("tokyonight.colors").setup(config)
local fishColors = {} local fishColors = {}
for k, v in pairs(colors) do if type(v) == "string" then fishColors[k] = v:gsub("^#", "") end end for k, v in pairs(colors) do
if type(v) == "string" then
fishColors[k] = v:gsub("^#", "")
end
end
local fish = util.template([[ local fish = util.template(
[[
# TokyoNight Color Palette # TokyoNight Color Palette
set -l foreground ${fg} set -l foreground ${fg}
set -l selection ${bg_visual} set -l selection ${bg_visual}
@@ -45,10 +50,11 @@ function M.fish(config)
set -g fish_pager_color_completion $foreground set -g fish_pager_color_completion $foreground
set -g fish_pager_color_description $comment set -g fish_pager_color_description $comment
]], fishColors) ]],
fishColors
)
return fish return fish
end end
return M return M

View File

@@ -29,4 +29,3 @@ config.style = "day"
write(kitty.kitty(config), "kitty_tokyonight_day.conf") write(kitty.kitty(config), "kitty_tokyonight_day.conf")
write(fish.fish(config), "fish_tokyonight_day.fish") write(fish.fish(config), "fish_tokyonight_day.fish")
write(alacritty.alacritty(config), "alacritty_tokyonight_day.yml") write(alacritty.alacritty(config), "alacritty_tokyonight_day.yml")

View File

@@ -7,7 +7,8 @@ function M.kitty(config)
config.transform_colors = true config.transform_colors = true
local colors = require("tokyonight.colors").setup(config) local colors = require("tokyonight.colors").setup(config)
local kitty = util.template([[ local kitty = util.template(
[[
# TokyoNight colors for Kitty # TokyoNight colors for Kitty
background ${bg} background ${bg}
@@ -47,9 +48,10 @@ function M.kitty(config)
# extended colors # extended colors
color16 ${orange} color16 ${orange}
color17 ${red1} color17 ${red1}
]], colors) ]],
colors
)
return kitty return kitty
end end
return M return M

View File

@@ -18,7 +18,8 @@ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE A
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]] local hsluv = {} ]]
local hsluv = {}
local hexChars = "0123456789abcdef" local hexChars = "0123456789abcdef"
@@ -31,24 +32,24 @@ local length_of_ray_until_intersect = function(theta, line)
end end
hsluv.get_bounds = function(l) hsluv.get_bounds = function(l)
local result = {}; local result = {}
local sub2; local sub2
local sub1 = ((l + 16) ^ 3) / 1560896; local sub1 = ((l + 16) ^ 3) / 1560896
if sub1 > hsluv.epsilon then if sub1 > hsluv.epsilon then
sub2 = sub1; sub2 = sub1
else else
sub2 = l / hsluv.kappa; sub2 = l / hsluv.kappa
end end
for i = 1, 3 do for i = 1, 3 do
local m1 = hsluv.m[i][1]; local m1 = hsluv.m[i][1]
local m2 = hsluv.m[i][2]; local m2 = hsluv.m[i][2]
local m3 = hsluv.m[i][3]; local m3 = hsluv.m[i][3]
for t = 0, 1 do for t = 0, 1 do
local top1 = (284517 * m1 - 94839 * m3) * sub2; local top1 = (284517 * m1 - 94839 * m3) * sub2
local top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * l * sub2 - 769860 * t * l; local top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * l * sub2 - 769860 * t * l
local bottom = (632260 * m3 - 126452 * m2) * sub2 + 126452 * t; local bottom = (632260 * m3 - 126452 * m2) * sub2 + 126452 * t
table.insert(result, { slope = top1 / bottom, intercept = top2 / bottom }) table.insert(result, { slope = top1 / bottom, intercept = top2 / bottom })
end end
end end
@@ -56,32 +57,38 @@ hsluv.get_bounds = function(l)
end end
hsluv.max_safe_chroma_for_l = function(l) hsluv.max_safe_chroma_for_l = function(l)
local bounds = hsluv.get_bounds(l); local bounds = hsluv.get_bounds(l)
local min = 1.7976931348623157e+308; local min = 1.7976931348623157e+308
for i = 1, 6 do for i = 1, 6 do
local length = distance_line_from_origin(bounds[i]); local length = distance_line_from_origin(bounds[i])
if length >= 0 then min = math.min(min, length); end if length >= 0 then
min = math.min(min, length)
end
end end
return min; return min
end end
hsluv.max_safe_chroma_for_lh = function(l, h) hsluv.max_safe_chroma_for_lh = function(l, h)
local hrad = h / 360 * math.pi * 2; local hrad = h / 360 * math.pi * 2
local bounds = hsluv.get_bounds(l); local bounds = hsluv.get_bounds(l)
local min = 1.7976931348623157e+308; local min = 1.7976931348623157e+308
for i = 1, 6 do for i = 1, 6 do
local bound = bounds[i]; local bound = bounds[i]
local length = length_of_ray_until_intersect(hrad, bound); local length = length_of_ray_until_intersect(hrad, bound)
if length >= 0 then min = math.min(min, length); end if length >= 0 then
min = math.min(min, length)
end
end end
return min return min
end end
hsluv.dot_product = function(a, b) hsluv.dot_product = function(a, b)
local sum = 0; local sum = 0
for i = 1, 3 do sum = sum + a[i] * b[i]; end for i = 1, 3 do
sum = sum + a[i] * b[i]
end
return sum return sum
end end
@@ -110,7 +117,7 @@ hsluv.xyz_to_rgb = function(tuple)
end end
hsluv.rgb_to_xyz = function(tuple) hsluv.rgb_to_xyz = function(tuple)
local rgbl = { hsluv.to_linear(tuple[1]), hsluv.to_linear(tuple[2]), hsluv.to_linear(tuple[3]) }; local rgbl = { hsluv.to_linear(tuple[1]), hsluv.to_linear(tuple[2]), hsluv.to_linear(tuple[3]) }
return { return {
hsluv.dot_product(hsluv.minv[1], rgbl), hsluv.dot_product(hsluv.minv[1], rgbl),
hsluv.dot_product(hsluv.minv[2], rgbl), hsluv.dot_product(hsluv.minv[2], rgbl),
@@ -135,102 +142,124 @@ hsluv.l_to_y = function(L)
end end
hsluv.xyz_to_luv = function(tuple) hsluv.xyz_to_luv = function(tuple)
local X = tuple[1]; local X = tuple[1]
local Y = tuple[2]; local Y = tuple[2]
local divider = X + 15 * Y + 3 * tuple[3]; local divider = X + 15 * Y + 3 * tuple[3]
local varU = 4 * X; local varU = 4 * X
local varV = 9 * Y; local varV = 9 * Y
if divider ~= 0 then if divider ~= 0 then
varU = varU / divider; varU = varU / divider
varV = varV / divider; varV = varV / divider
else else
varU = 0; varU = 0
varV = 0; varV = 0
end
local L = hsluv.y_to_l(Y)
if L == 0 then
return { 0, 0, 0 }
end end
local L = hsluv.y_to_l(Y);
if L == 0 then return { 0, 0, 0 } end
return { L, 13 * L * (varU - hsluv.refU), 13 * L * (varV - hsluv.refV) } return { L, 13 * L * (varU - hsluv.refU), 13 * L * (varV - hsluv.refV) }
end end
hsluv.luv_to_xyz = function(tuple) hsluv.luv_to_xyz = function(tuple)
local L = tuple[1]; local L = tuple[1]
local U = tuple[2]; local U = tuple[2]
local V = tuple[3]; local V = tuple[3]
if L == 0 then return { 0, 0, 0 } end if L == 0 then
local varU = U / (13 * L) + hsluv.refU; return { 0, 0, 0 }
local varV = V / (13 * L) + hsluv.refV; end
local Y = hsluv.l_to_y(L); local varU = U / (13 * L) + hsluv.refU
local X = 0 - (9 * Y * varU) / ((((varU - 4) * varV) - varU * varV)); local varV = V / (13 * L) + hsluv.refV
local Y = hsluv.l_to_y(L)
local X = 0 - (9 * Y * varU) / (((varU - 4) * varV) - varU * varV)
return { X, Y, (9 * Y - 15 * varV * Y - varV * X) / (3 * varV) } return { X, Y, (9 * Y - 15 * varV * Y - varV * X) / (3 * varV) }
end end
hsluv.luv_to_lch = function(tuple) hsluv.luv_to_lch = function(tuple)
local L = tuple[1]; local L = tuple[1]
local U = tuple[2]; local U = tuple[2]
local V = tuple[3]; local V = tuple[3]
local C = math.sqrt(U * U + V * V); local C = math.sqrt(U * U + V * V)
local H local H
if C < 0.00000001 then if C < 0.00000001 then
H = 0; H = 0
else else
H = math.atan2(V, U) * 180.0 / 3.1415926535897932; H = math.atan2(V, U) * 180.0 / 3.1415926535897932
if H < 0 then H = 360 + H; end if H < 0 then
H = 360 + H
end
end end
return { L, C, H } return { L, C, H }
end end
hsluv.lch_to_luv = function(tuple) hsluv.lch_to_luv = function(tuple)
local L = tuple[1]; local L = tuple[1]
local C = tuple[2]; local C = tuple[2]
local Hrad = tuple[3] / 360.0 * 2 * math.pi; local Hrad = tuple[3] / 360.0 * 2 * math.pi
return { L, math.cos(Hrad) * C, math.sin(Hrad) * C }; return { L, math.cos(Hrad) * C, math.sin(Hrad) * C }
end end
hsluv.hsluv_to_lch = function(tuple) hsluv.hsluv_to_lch = function(tuple)
local H = tuple[1]; local H = tuple[1]
local S = tuple[2]; local S = tuple[2]
local L = tuple[3]; local L = tuple[3]
if L > 99.9999999 then return { 100, 0, H } end if L > 99.9999999 then
if L < 0.00000001 then return { 0, 0, H } end return { 100, 0, H }
end
if L < 0.00000001 then
return { 0, 0, H }
end
return { L, hsluv.max_safe_chroma_for_lh(L, H) / 100 * S, H } return { L, hsluv.max_safe_chroma_for_lh(L, H) / 100 * S, H }
end end
hsluv.lch_to_hsluv = function(tuple) hsluv.lch_to_hsluv = function(tuple)
local L = tuple[1]; local L = tuple[1]
local C = tuple[2]; local C = tuple[2]
local H = tuple[3]; local H = tuple[3]
local max_chroma = hsluv.max_safe_chroma_for_lh(L, H) local max_chroma = hsluv.max_safe_chroma_for_lh(L, H)
if L > 99.9999999 then return { H, 0, 100 } end if L > 99.9999999 then
if L < 0.00000001 then return { H, 0, 0 } end return { H, 0, 100 }
end
if L < 0.00000001 then
return { H, 0, 0 }
end
return { H, C / max_chroma * 100, L } return { H, C / max_chroma * 100, L }
end end
hsluv.hpluv_to_lch = function(tuple) hsluv.hpluv_to_lch = function(tuple)
local H = tuple[1]; local H = tuple[1]
local S = tuple[2]; local S = tuple[2]
local L = tuple[3]; local L = tuple[3]
if L > 99.9999999 then return { 100, 0, H } end if L > 99.9999999 then
if L < 0.00000001 then return { 0, 0, H } end return { 100, 0, H }
end
if L < 0.00000001 then
return { 0, 0, H }
end
return { L, hsluv.max_safe_chroma_for_l(L) / 100 * S, H } return { L, hsluv.max_safe_chroma_for_l(L) / 100 * S, H }
end end
hsluv.lch_to_hpluv = function(tuple) hsluv.lch_to_hpluv = function(tuple)
local L = tuple[1]; local L = tuple[1]
local C = tuple[2]; local C = tuple[2]
local H = tuple[3]; local H = tuple[3]
if L > 99.9999999 then return { H, 0, 100 } end if L > 99.9999999 then
if L < 0.00000001 then return { H, 0, 0 } end return { H, 0, 100 }
end
if L < 0.00000001 then
return { H, 0, 0 }
end
return { H, C / hsluv.max_safe_chroma_for_l(L) * 100, L } return { H, C / hsluv.max_safe_chroma_for_l(L) * 100, L }
end end
hsluv.rgb_to_hex = function(tuple) hsluv.rgb_to_hex = function(tuple)
local h = "#"; local h = "#"
for i = 1, 3 do for i = 1, 3 do
local c = math.floor(tuple[i] * 255 + 0.5); local c = math.floor(tuple[i] * 255 + 0.5)
local digit2 = math.fmod(c, 16); local digit2 = math.fmod(c, 16)
local x = (c - digit2) / 16; local x = (c - digit2) / 16
local digit1 = math.floor(x); local digit1 = math.floor(x)
h = h .. string.sub(hexChars, digit1 + 1, digit1 + 1) h = h .. string.sub(hexChars, digit1 + 1, digit1 + 1)
h = h .. string.sub(hexChars, digit2 + 1, digit2 + 1) h = h .. string.sub(hexChars, digit2 + 1, digit2 + 1)
end end
@@ -241,36 +270,54 @@ hsluv.hex_to_rgb = function(hex)
hex = string.lower(hex) hex = string.lower(hex)
local ret = {} local ret = {}
for i = 0, 2 do for i = 0, 2 do
local char1 = string.sub(hex, i * 2 + 2, i * 2 + 2); local char1 = string.sub(hex, i * 2 + 2, i * 2 + 2)
local char2 = string.sub(hex, i * 2 + 3, i * 2 + 3); local char2 = string.sub(hex, i * 2 + 3, i * 2 + 3)
local digit1 = string.find(hexChars, char1) - 1 local digit1 = string.find(hexChars, char1) - 1
local digit2 = string.find(hexChars, char2) - 1 local digit2 = string.find(hexChars, char2) - 1
ret[i + 1] = (digit1 * 16 + digit2) / 255.0; ret[i + 1] = (digit1 * 16 + digit2) / 255.0
end end
return ret return ret
end end
hsluv.lch_to_rgb = function(tuple) return hsluv.lch_to_rgb = function(tuple)
hsluv.xyz_to_rgb(hsluv.luv_to_xyz(hsluv.lch_to_luv(tuple))) end return hsluv.xyz_to_rgb(hsluv.luv_to_xyz(hsluv.lch_to_luv(tuple)))
end
hsluv.rgb_to_lch = function(tuple) return hsluv.rgb_to_lch = function(tuple)
hsluv.luv_to_lch(hsluv.xyz_to_luv(hsluv.rgb_to_xyz(tuple))) end return hsluv.luv_to_lch(hsluv.xyz_to_luv(hsluv.rgb_to_xyz(tuple)))
end
hsluv.hsluv_to_rgb = function(tuple) return hsluv.lch_to_rgb(hsluv.hsluv_to_lch(tuple)) end hsluv.hsluv_to_rgb = function(tuple)
return hsluv.lch_to_rgb(hsluv.hsluv_to_lch(tuple))
end
hsluv.rgb_to_hsluv = function(tuple) return hsluv.lch_to_hsluv(hsluv.rgb_to_lch(tuple)) end hsluv.rgb_to_hsluv = function(tuple)
return hsluv.lch_to_hsluv(hsluv.rgb_to_lch(tuple))
end
hsluv.hpluv_to_rgb = function(tuple) return hsluv.lch_to_rgb(hsluv.hpluv_to_lch(tuple)) end hsluv.hpluv_to_rgb = function(tuple)
return hsluv.lch_to_rgb(hsluv.hpluv_to_lch(tuple))
end
hsluv.rgb_to_hpluv = function(tuple) return hsluv.lch_to_hpluv(hsluv.rgb_to_lch(tuple)) end hsluv.rgb_to_hpluv = function(tuple)
return hsluv.lch_to_hpluv(hsluv.rgb_to_lch(tuple))
end
hsluv.hsluv_to_hex = function(tuple) return hsluv.rgb_to_hex(hsluv.hsluv_to_rgb(tuple)) end hsluv.hsluv_to_hex = function(tuple)
return hsluv.rgb_to_hex(hsluv.hsluv_to_rgb(tuple))
end
hsluv.hpluv_to_hex = function(tuple) return hsluv.rgb_to_hex(hsluv.hpluv_to_rgb(tuple)) end hsluv.hpluv_to_hex = function(tuple)
return hsluv.rgb_to_hex(hsluv.hpluv_to_rgb(tuple))
end
hsluv.hex_to_hsluv = function(s) return hsluv.rgb_to_hsluv(hsluv.hex_to_rgb(s)) end hsluv.hex_to_hsluv = function(s)
return hsluv.rgb_to_hsluv(hsluv.hex_to_rgb(s))
end
hsluv.hex_to_hpluv = function(s) return hsluv.rgb_to_hpluv(hsluv.hex_to_rgb(s)) end hsluv.hex_to_hpluv = function(s)
return hsluv.rgb_to_hpluv(hsluv.hex_to_rgb(s))
end
hsluv.m = { hsluv.m = {
{ 3.240969941904521, -1.537383177570093, -0.498610760293 }, { 3.240969941904521, -1.537383177570093, -0.498610760293 },

View File

@@ -3,7 +3,8 @@ local theme = require("tokyonight.theme")
local M = {} local M = {}
function M.colorscheme() util.load(theme.setup()) end function M.colorscheme()
util.load(theme.setup())
end
return M return M

View File

@@ -27,20 +27,26 @@ function util.blend(fg, bg, alpha)
fg = hexToRgb(fg) fg = hexToRgb(fg)
local blendChannel = function(i) local blendChannel = function(i)
local ret = (alpha * (fg[i]) + ((1 - alpha) * (bg[i]))) local ret = (alpha * fg[i] + ((1 - alpha) * bg[i]))
return math.floor(math.min(math.max(0, ret), 255) + .5) return math.floor(math.min(math.max(0, ret), 255) + 0.5)
end end
return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3)) return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3))
end end
function util.darken(hex, amount, bg) return util.blend(hex, bg or util.bg, math.abs(amount)) end function util.darken(hex, amount, bg)
function util.lighten(hex, amount, fg) return util.blend(hex, fg or util.fg, math.abs(amount)) end return util.blend(hex, bg or util.bg, math.abs(amount))
end
function util.lighten(hex, amount, fg)
return util.blend(hex, fg or util.fg, math.abs(amount))
end
function util.brighten(color, percentage) function util.brighten(color, percentage)
local hsl = hsluv.hex_to_hsluv(color) local hsl = hsluv.hex_to_hsluv(color)
local larpSpace = 100 - hsl[3] local larpSpace = 100 - hsl[3]
if percentage < 0 then larpSpace = hsl[3] end if percentage < 0 then
larpSpace = hsl[3]
end
hsl[3] = hsl[3] + larpSpace * percentage hsl[3] = hsl[3] + larpSpace * percentage
return hsluv.hsluv_to_hex(hsl) return hsluv.hsluv_to_hex(hsl)
end end
@@ -49,7 +55,9 @@ function util.invertColor(color)
if color ~= "NONE" then if color ~= "NONE" then
local hsl = hsluv.hex_to_hsluv(color) local hsl = hsluv.hex_to_hsluv(color)
hsl[3] = 100 - hsl[3] hsl[3] = 100 - hsl[3]
if hsl[3] < 40 then hsl[3] = hsl[3] + (100 - hsl[3]) * .3 end if hsl[3] < 40 then
hsl[3] = hsl[3] + (100 - hsl[3]) * 0.3
end
return hsluv.hsluv_to_hex(hsl) return hsluv.hsluv_to_hex(hsl)
end end
return color return color
@@ -65,16 +73,26 @@ function util.randomColor(color)
end end
function util.getColor(color) function util.getColor(color)
if vim.o.background == "dark" then return color end if vim.o.background == "dark" then
if not util.colorCache[color] then util.colorCache[color] = util.invertColor(color) end return color
end
if not util.colorCache[color] then
util.colorCache[color] = util.invertColor(color)
end
return util.colorCache[color] return util.colorCache[color]
end end
-- local ns = vim.api.nvim_create_namespace("tokyonight") -- local ns = vim.api.nvim_create_namespace("tokyonight")
function util.highlight(group, color) function util.highlight(group, color)
if color.fg then util.colorsUsed[color.fg] = true end if color.fg then
if color.bg then util.colorsUsed[color.bg] = true end util.colorsUsed[color.fg] = true
if color.sp then util.colorsUsed[color.sp] = true end end
if color.bg then
util.colorsUsed[color.bg] = true
end
if color.sp then
util.colorsUsed[color.sp] = true
end
local style = color.style and "gui=" .. color.style or "gui=NONE" local style = color.style and "gui=" .. color.style or "gui=NONE"
local fg = color.fg and "guifg=" .. util.getColor(color.fg) or "guifg=NONE" local fg = color.fg and "guifg=" .. util.getColor(color.fg) or "guifg=NONE"
@@ -103,7 +121,9 @@ function util.debug(colors)
if type(color) == "table" then if type(color) == "table" then
util.debug(color) util.debug(color)
else else
if util.colorsUsed[color] == nil then print("not used: " .. name .. " : " .. color) end if util.colorsUsed[color] == nil then
print("not used: " .. name .. " : " .. color)
end
end end
end end
end end
@@ -111,28 +131,27 @@ end
--- Delete the autocmds when the theme changes to something else --- Delete the autocmds when the theme changes to something else
function util.onColorScheme() function util.onColorScheme()
if vim.g.colors_name ~= "tokyonight" then if vim.g.colors_name ~= "tokyonight" then
vim.cmd [[autocmd! TokyoNight]] vim.cmd([[autocmd! TokyoNight]])
vim.cmd [[augroup! TokyoNight]] vim.cmd([[augroup! TokyoNight]])
end end
end end
---@param config Config ---@param config Config
function util.autocmds(config) function util.autocmds(config)
vim.cmd [[augroup TokyoNight]] vim.cmd([[augroup TokyoNight]])
vim.cmd [[ autocmd!]] vim.cmd([[ autocmd!]])
vim.cmd [[ autocmd ColorScheme * lua require("tokyonight.util").onColorScheme()]] vim.cmd([[ autocmd ColorScheme * lua require("tokyonight.util").onColorScheme()]])
if config.dev then if config.dev then
vim.cmd [[ autocmd BufWritePost */lua/tokyonight/** nested colorscheme tokyonight]] vim.cmd([[ autocmd BufWritePost */lua/tokyonight/** nested colorscheme tokyonight]])
end end
for _, sidebar in ipairs(config.sidebars) do for _, sidebar in ipairs(config.sidebars) do
if sidebar == "terminal" then if sidebar == "terminal" then
vim.cmd [[ autocmd TermOpen * setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]] vim.cmd([[ autocmd TermOpen * setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]])
else else
vim.cmd([[ autocmd FileType ]] .. sidebar .. vim.cmd([[ autocmd FileType ]] .. sidebar .. [[ setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]])
[[ setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]])
end end
end end
vim.cmd [[augroup end]] vim.cmd([[augroup end]])
end end
-- Simple string interpolation. -- Simple string interpolation.
@@ -142,10 +161,16 @@ end
---@param str string template string ---@param str string template string
---@param table table key value pairs to replace in the string ---@param table table key value pairs to replace in the string
function util.template(str, table) function util.template(str, table)
return (str:gsub("($%b{})", function(w) return table[w:sub(3, -2)] or w end)) return (str:gsub("($%b{})", function(w)
return table[w:sub(3, -2)] or w
end))
end end
function util.syntax(syntax) for group, colors in pairs(syntax) do util.highlight(group, colors) end end function util.syntax(syntax)
for group, colors in pairs(syntax) do
util.highlight(group, colors)
end
end
---@param colors ColorScheme ---@param colors ColorScheme
function util.terminal(colors) function util.terminal(colors)
@@ -184,16 +209,22 @@ function util.terminal(colors)
end end
function util.light_colors(colors) function util.light_colors(colors)
if type(colors) == "string" then return util.getColor(colors) end if type(colors) == "string" then
return util.getColor(colors)
end
local ret = {} local ret = {}
for key, value in pairs(colors) do ret[key] = util.light_colors(value) end for key, value in pairs(colors) do
ret[key] = util.light_colors(value)
end
return ret return ret
end end
---@param theme Theme ---@param theme Theme
function util.load(theme) function util.load(theme)
vim.cmd("hi clear") vim.cmd("hi clear")
if vim.fn.exists("syntax_on") then vim.cmd("syntax reset") 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"
@@ -214,13 +245,17 @@ end
function util.color_overrides(colors, config) function util.color_overrides(colors, config)
if type(config.colors) == "table" then if type(config.colors) == "table" then
for key, value in pairs(config.colors) do for key, value in pairs(config.colors) do
if not colors[key] then error("Color " .. key .. " does not exist") end if not colors[key] then
error("Color " .. key .. " does not exist")
end
if string.sub(value, 1, 1) == "#" then if string.sub(value, 1, 1) == "#" then
-- hex override -- hex override
colors[key] = value colors[key] = value
else else
-- another group -- another group
if not colors[value] then error("Color " .. value .. " does not exist") end if not colors[value] then
error("Color " .. value .. " does not exist")
end
colors[key] = colors[value] colors[key] = colors[value]
end end
end end
@@ -234,13 +269,17 @@ function util.light(brightness)
if type(hl[key]) == "number" then if type(hl[key]) == "number" then
local hex = string.format("#%06x", hl[key]) local hex = string.format("#%06x", hl[key])
local color = util.invertColor(hex) local color = util.invertColor(hex)
if brightness then color = util.brighten(hex, brightness) end if brightness then
color = util.brighten(hex, brightness)
end
table.insert(def, "gui" .. def_key .. "=" .. color) table.insert(def, "gui" .. def_key .. "=" .. color)
end end
end end
if hl_name ~= "" and #def > 0 then if hl_name ~= "" and #def > 0 then
for _, style in pairs({ "bold", "italic", "underline", "undercurl", "reverse" }) do for _, style in pairs({ "bold", "italic", "underline", "undercurl", "reverse" }) do
if hl[style] then table.insert(def, "gui=" .. style) end if hl[style] then
table.insert(def, "gui=" .. style)
end
end end
vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " ")) vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " "))
@@ -262,7 +301,9 @@ function util.random()
end end
if hl_name ~= "" and #def > 0 then if hl_name ~= "" and #def > 0 then
for _, style in pairs({ "bold", "italic", "underline", "undercurl", "reverse" }) do for _, style in pairs({ "bold", "italic", "underline", "undercurl", "reverse" }) do
if hl[style] then table.insert(def, "gui=" .. style) end if hl[style] then
table.insert(def, "gui=" .. style)
end
end end
vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " ")) vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " "))
@@ -271,4 +312,3 @@ function util.random()
end end
return util return util

1
selene.toml Normal file
View File

@@ -0,0 +1 @@
std="lua51+vim"

3
stylua.toml Normal file
View File

@@ -0,0 +1,3 @@
indent_type = "Spaces"
indent_width = 2
column_width = 120

2
vim.toml Normal file
View File

@@ -0,0 +1,2 @@
[vim]
any = true