build: selene + stylua
This commit is contained in:
@@ -39,8 +39,12 @@ tokyonight.inactive = {
|
||||
if vim.o.background == "light" then
|
||||
for _, mode in pairs(tokyonight) do
|
||||
for _, section in pairs(mode) do
|
||||
if section.bg then section.bg = util.getColor(section.bg) end
|
||||
if section.fg then section.fg = util.getColor(section.fg) end
|
||||
if section.bg then
|
||||
section.bg = util.getColor(section.bg)
|
||||
end
|
||||
if section.fg then
|
||||
section.fg = util.getColor(section.fg)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,16 +49,16 @@ function M.setup(config)
|
||||
util.bg = colors.bg
|
||||
|
||||
colors.diff = {
|
||||
add = util.darken(colors.green2, .15),
|
||||
delete = util.darken(colors.red1, .15),
|
||||
change = util.darken(colors.blue7, .15),
|
||||
add = util.darken(colors.green2, 0.15),
|
||||
delete = util.darken(colors.red1, 0.15),
|
||||
change = util.darken(colors.blue7, 0.15),
|
||||
text = colors.blue7,
|
||||
}
|
||||
|
||||
colors.gitSigns = {
|
||||
add = util.brighten(colors.diff.add, .2),
|
||||
change = util.brighten(colors.diff.change, .2),
|
||||
delete = util.brighten(colors.diff.delete, .2),
|
||||
add = util.brighten(colors.diff.add, 0.2),
|
||||
change = util.brighten(colors.diff.change, 0.2),
|
||||
delete = util.brighten(colors.diff.delete, 0.2),
|
||||
}
|
||||
|
||||
colors.git.ignore = colors.dark3
|
||||
@@ -93,4 +93,3 @@ function M.setup(config)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
|
||||
@@ -6,8 +6,12 @@ vim = vim or { g = {}, o = {} }
|
||||
|
||||
local function opt(key, default)
|
||||
key = "tokyonight_" .. key
|
||||
if vim.g[key] == nil then return default end
|
||||
if vim.g[key] == 0 then return false end
|
||||
if vim.g[key] == nil then
|
||||
return default
|
||||
end
|
||||
if vim.g[key] == 0 then
|
||||
return false
|
||||
end
|
||||
return vim.g[key]
|
||||
end
|
||||
|
||||
@@ -28,6 +32,8 @@ config = {
|
||||
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
|
||||
|
||||
@@ -9,10 +9,13 @@ function M.alacritty(config)
|
||||
|
||||
local alacrittyColors = {}
|
||||
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
|
||||
|
||||
local alacritty = util.template([[
|
||||
local alacritty = util.template(
|
||||
[[
|
||||
# TokyoNight Alacritty Colors
|
||||
colors:
|
||||
# Default colors
|
||||
@@ -46,10 +49,11 @@ colors:
|
||||
- { index: 16, color: '${orange}' }
|
||||
- { index: 17, color: '${red1}' }
|
||||
|
||||
]], alacrittyColors)
|
||||
]],
|
||||
alacrittyColors
|
||||
)
|
||||
|
||||
return alacritty
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
|
||||
@@ -8,9 +8,14 @@ function M.fish(config)
|
||||
local colors = require("tokyonight.colors").setup(config)
|
||||
|
||||
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
|
||||
set -l foreground ${fg}
|
||||
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_description $comment
|
||||
|
||||
]], fishColors)
|
||||
]],
|
||||
fishColors
|
||||
)
|
||||
|
||||
return fish
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
|
||||
@@ -29,4 +29,3 @@ config.style = "day"
|
||||
write(kitty.kitty(config), "kitty_tokyonight_day.conf")
|
||||
write(fish.fish(config), "fish_tokyonight_day.fish")
|
||||
write(alacritty.alacritty(config), "alacritty_tokyonight_day.yml")
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ function M.kitty(config)
|
||||
config.transform_colors = true
|
||||
local colors = require("tokyonight.colors").setup(config)
|
||||
|
||||
local kitty = util.template([[
|
||||
local kitty = util.template(
|
||||
[[
|
||||
# TokyoNight colors for Kitty
|
||||
|
||||
background ${bg}
|
||||
@@ -47,9 +48,10 @@ function M.kitty(config)
|
||||
# extended colors
|
||||
color16 ${orange}
|
||||
color17 ${red1}
|
||||
]], colors)
|
||||
]],
|
||||
colors
|
||||
)
|
||||
return kitty
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
|
||||
@@ -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,
|
||||
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.
|
||||
]] local hsluv = {}
|
||||
]]
|
||||
local hsluv = {}
|
||||
|
||||
local hexChars = "0123456789abcdef"
|
||||
|
||||
@@ -31,24 +32,24 @@ local length_of_ray_until_intersect = function(theta, line)
|
||||
end
|
||||
|
||||
hsluv.get_bounds = function(l)
|
||||
local result = {};
|
||||
local sub2;
|
||||
local sub1 = ((l + 16) ^ 3) / 1560896;
|
||||
local result = {}
|
||||
local sub2
|
||||
local sub1 = ((l + 16) ^ 3) / 1560896
|
||||
if sub1 > hsluv.epsilon then
|
||||
sub2 = sub1;
|
||||
sub2 = sub1
|
||||
else
|
||||
sub2 = l / hsluv.kappa;
|
||||
sub2 = l / hsluv.kappa
|
||||
end
|
||||
|
||||
for i = 1, 3 do
|
||||
local m1 = hsluv.m[i][1];
|
||||
local m2 = hsluv.m[i][2];
|
||||
local m3 = hsluv.m[i][3];
|
||||
local m1 = hsluv.m[i][1]
|
||||
local m2 = hsluv.m[i][2]
|
||||
local m3 = hsluv.m[i][3]
|
||||
|
||||
for t = 0, 1 do
|
||||
local top1 = (284517 * m1 - 94839 * m3) * sub2;
|
||||
local top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * l * sub2 - 769860 * t * l;
|
||||
local bottom = (632260 * m3 - 126452 * m2) * sub2 + 126452 * t;
|
||||
local top1 = (284517 * m1 - 94839 * m3) * sub2
|
||||
local top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * l * sub2 - 769860 * t * l
|
||||
local bottom = (632260 * m3 - 126452 * m2) * sub2 + 126452 * t
|
||||
table.insert(result, { slope = top1 / bottom, intercept = top2 / bottom })
|
||||
end
|
||||
end
|
||||
@@ -56,32 +57,38 @@ hsluv.get_bounds = function(l)
|
||||
end
|
||||
|
||||
hsluv.max_safe_chroma_for_l = function(l)
|
||||
local bounds = hsluv.get_bounds(l);
|
||||
local min = 1.7976931348623157e+308;
|
||||
local bounds = hsluv.get_bounds(l)
|
||||
local min = 1.7976931348623157e+308
|
||||
|
||||
for i = 1, 6 do
|
||||
local length = distance_line_from_origin(bounds[i]);
|
||||
if length >= 0 then min = math.min(min, length); end
|
||||
local length = distance_line_from_origin(bounds[i])
|
||||
if length >= 0 then
|
||||
min = math.min(min, length)
|
||||
end
|
||||
end
|
||||
return min;
|
||||
return min
|
||||
end
|
||||
|
||||
hsluv.max_safe_chroma_for_lh = function(l, h)
|
||||
local hrad = h / 360 * math.pi * 2;
|
||||
local bounds = hsluv.get_bounds(l);
|
||||
local min = 1.7976931348623157e+308;
|
||||
local hrad = h / 360 * math.pi * 2
|
||||
local bounds = hsluv.get_bounds(l)
|
||||
local min = 1.7976931348623157e+308
|
||||
|
||||
for i = 1, 6 do
|
||||
local bound = bounds[i];
|
||||
local length = length_of_ray_until_intersect(hrad, bound);
|
||||
if length >= 0 then min = math.min(min, length); end
|
||||
local bound = bounds[i]
|
||||
local length = length_of_ray_until_intersect(hrad, bound)
|
||||
if length >= 0 then
|
||||
min = math.min(min, length)
|
||||
end
|
||||
end
|
||||
return min
|
||||
end
|
||||
|
||||
hsluv.dot_product = function(a, b)
|
||||
local sum = 0;
|
||||
for i = 1, 3 do sum = sum + a[i] * b[i]; end
|
||||
local sum = 0
|
||||
for i = 1, 3 do
|
||||
sum = sum + a[i] * b[i]
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
@@ -110,7 +117,7 @@ hsluv.xyz_to_rgb = function(tuple)
|
||||
end
|
||||
|
||||
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 {
|
||||
hsluv.dot_product(hsluv.minv[1], rgbl),
|
||||
hsluv.dot_product(hsluv.minv[2], rgbl),
|
||||
@@ -135,102 +142,124 @@ hsluv.l_to_y = function(L)
|
||||
end
|
||||
|
||||
hsluv.xyz_to_luv = function(tuple)
|
||||
local X = tuple[1];
|
||||
local Y = tuple[2];
|
||||
local divider = X + 15 * Y + 3 * tuple[3];
|
||||
local varU = 4 * X;
|
||||
local varV = 9 * Y;
|
||||
local X = tuple[1]
|
||||
local Y = tuple[2]
|
||||
local divider = X + 15 * Y + 3 * tuple[3]
|
||||
local varU = 4 * X
|
||||
local varV = 9 * Y
|
||||
if divider ~= 0 then
|
||||
varU = varU / divider;
|
||||
varV = varV / divider;
|
||||
varU = varU / divider
|
||||
varV = varV / divider
|
||||
else
|
||||
varU = 0;
|
||||
varV = 0;
|
||||
varU = 0
|
||||
varV = 0
|
||||
end
|
||||
local L = hsluv.y_to_l(Y)
|
||||
if L == 0 then
|
||||
return { 0, 0, 0 }
|
||||
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) }
|
||||
end
|
||||
|
||||
hsluv.luv_to_xyz = function(tuple)
|
||||
local L = tuple[1];
|
||||
local U = tuple[2];
|
||||
local V = tuple[3];
|
||||
if L == 0 then return { 0, 0, 0 } end
|
||||
local varU = U / (13 * L) + hsluv.refU;
|
||||
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));
|
||||
local L = tuple[1]
|
||||
local U = tuple[2]
|
||||
local V = tuple[3]
|
||||
if L == 0 then
|
||||
return { 0, 0, 0 }
|
||||
end
|
||||
local varU = U / (13 * L) + hsluv.refU
|
||||
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) }
|
||||
end
|
||||
|
||||
hsluv.luv_to_lch = function(tuple)
|
||||
local L = tuple[1];
|
||||
local U = tuple[2];
|
||||
local V = tuple[3];
|
||||
local C = math.sqrt(U * U + V * V);
|
||||
local L = tuple[1]
|
||||
local U = tuple[2]
|
||||
local V = tuple[3]
|
||||
local C = math.sqrt(U * U + V * V)
|
||||
local H
|
||||
if C < 0.00000001 then
|
||||
H = 0;
|
||||
H = 0
|
||||
else
|
||||
H = math.atan2(V, U) * 180.0 / 3.1415926535897932;
|
||||
if H < 0 then H = 360 + H; end
|
||||
H = math.atan2(V, U) * 180.0 / 3.1415926535897932
|
||||
if H < 0 then
|
||||
H = 360 + H
|
||||
end
|
||||
end
|
||||
return { L, C, H }
|
||||
end
|
||||
|
||||
hsluv.lch_to_luv = function(tuple)
|
||||
local L = tuple[1];
|
||||
local C = tuple[2];
|
||||
local Hrad = tuple[3] / 360.0 * 2 * math.pi;
|
||||
return { L, math.cos(Hrad) * C, math.sin(Hrad) * C };
|
||||
local L = tuple[1]
|
||||
local C = tuple[2]
|
||||
local Hrad = tuple[3] / 360.0 * 2 * math.pi
|
||||
return { L, math.cos(Hrad) * C, math.sin(Hrad) * C }
|
||||
end
|
||||
|
||||
hsluv.hsluv_to_lch = function(tuple)
|
||||
local H = tuple[1];
|
||||
local S = tuple[2];
|
||||
local L = tuple[3];
|
||||
if L > 99.9999999 then return { 100, 0, H } end
|
||||
if L < 0.00000001 then return { 0, 0, H } end
|
||||
local H = tuple[1]
|
||||
local S = tuple[2]
|
||||
local L = tuple[3]
|
||||
if L > 99.9999999 then
|
||||
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 }
|
||||
end
|
||||
|
||||
hsluv.lch_to_hsluv = function(tuple)
|
||||
local L = tuple[1];
|
||||
local C = tuple[2];
|
||||
local H = tuple[3];
|
||||
local L = tuple[1]
|
||||
local C = tuple[2]
|
||||
local H = tuple[3]
|
||||
local max_chroma = hsluv.max_safe_chroma_for_lh(L, H)
|
||||
if L > 99.9999999 then return { H, 0, 100 } end
|
||||
if L < 0.00000001 then return { H, 0, 0 } end
|
||||
if L > 99.9999999 then
|
||||
return { H, 0, 100 }
|
||||
end
|
||||
if L < 0.00000001 then
|
||||
return { H, 0, 0 }
|
||||
end
|
||||
|
||||
return { H, C / max_chroma * 100, L }
|
||||
end
|
||||
|
||||
hsluv.hpluv_to_lch = function(tuple)
|
||||
local H = tuple[1];
|
||||
local S = tuple[2];
|
||||
local L = tuple[3];
|
||||
if L > 99.9999999 then return { 100, 0, H } end
|
||||
if L < 0.00000001 then return { 0, 0, H } end
|
||||
local H = tuple[1]
|
||||
local S = tuple[2]
|
||||
local L = tuple[3]
|
||||
if L > 99.9999999 then
|
||||
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 }
|
||||
end
|
||||
|
||||
hsluv.lch_to_hpluv = function(tuple)
|
||||
local L = tuple[1];
|
||||
local C = tuple[2];
|
||||
local H = tuple[3];
|
||||
if L > 99.9999999 then return { H, 0, 100 } end
|
||||
if L < 0.00000001 then return { H, 0, 0 } end
|
||||
local L = tuple[1]
|
||||
local C = tuple[2]
|
||||
local H = tuple[3]
|
||||
if L > 99.9999999 then
|
||||
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 }
|
||||
end
|
||||
|
||||
hsluv.rgb_to_hex = function(tuple)
|
||||
local h = "#";
|
||||
local h = "#"
|
||||
for i = 1, 3 do
|
||||
local c = math.floor(tuple[i] * 255 + 0.5);
|
||||
local digit2 = math.fmod(c, 16);
|
||||
local x = (c - digit2) / 16;
|
||||
local digit1 = math.floor(x);
|
||||
local c = math.floor(tuple[i] * 255 + 0.5)
|
||||
local digit2 = math.fmod(c, 16)
|
||||
local x = (c - digit2) / 16
|
||||
local digit1 = math.floor(x)
|
||||
h = h .. string.sub(hexChars, digit1 + 1, digit1 + 1)
|
||||
h = h .. string.sub(hexChars, digit2 + 1, digit2 + 1)
|
||||
end
|
||||
@@ -241,36 +270,54 @@ hsluv.hex_to_rgb = function(hex)
|
||||
hex = string.lower(hex)
|
||||
local ret = {}
|
||||
for i = 0, 2 do
|
||||
local char1 = string.sub(hex, i * 2 + 2, i * 2 + 2);
|
||||
local char2 = string.sub(hex, i * 2 + 3, i * 2 + 3);
|
||||
local char1 = string.sub(hex, i * 2 + 2, i * 2 + 2)
|
||||
local char2 = string.sub(hex, i * 2 + 3, i * 2 + 3)
|
||||
local digit1 = string.find(hexChars, char1) - 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
|
||||
return ret
|
||||
end
|
||||
|
||||
hsluv.lch_to_rgb = function(tuple) return
|
||||
hsluv.xyz_to_rgb(hsluv.luv_to_xyz(hsluv.lch_to_luv(tuple))) end
|
||||
hsluv.lch_to_rgb = function(tuple)
|
||||
return hsluv.xyz_to_rgb(hsluv.luv_to_xyz(hsluv.lch_to_luv(tuple)))
|
||||
end
|
||||
|
||||
hsluv.rgb_to_lch = function(tuple) return
|
||||
hsluv.luv_to_lch(hsluv.xyz_to_luv(hsluv.rgb_to_xyz(tuple))) end
|
||||
hsluv.rgb_to_lch = function(tuple)
|
||||
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 = {
|
||||
{ 3.240969941904521, -1.537383177570093, -0.498610760293 },
|
||||
|
||||
@@ -3,7 +3,8 @@ local theme = require("tokyonight.theme")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.colorscheme() util.load(theme.setup()) end
|
||||
function M.colorscheme()
|
||||
util.load(theme.setup())
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
|
||||
@@ -27,20 +27,26 @@ function util.blend(fg, bg, alpha)
|
||||
fg = hexToRgb(fg)
|
||||
|
||||
local blendChannel = function(i)
|
||||
local ret = (alpha * (fg[i]) + ((1 - alpha) * (bg[i])))
|
||||
return math.floor(math.min(math.max(0, ret), 255) + .5)
|
||||
local ret = (alpha * fg[i] + ((1 - alpha) * bg[i]))
|
||||
return math.floor(math.min(math.max(0, ret), 255) + 0.5)
|
||||
end
|
||||
|
||||
return string.format("#%02X%02X%02X", blendChannel(1), blendChannel(2), blendChannel(3))
|
||||
end
|
||||
|
||||
function util.darken(hex, amount, bg) 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.darken(hex, amount, bg)
|
||||
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)
|
||||
local hsl = hsluv.hex_to_hsluv(color)
|
||||
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
|
||||
return hsluv.hsluv_to_hex(hsl)
|
||||
end
|
||||
@@ -49,7 +55,9 @@ function util.invertColor(color)
|
||||
if color ~= "NONE" then
|
||||
local hsl = hsluv.hex_to_hsluv(color)
|
||||
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)
|
||||
end
|
||||
return color
|
||||
@@ -65,16 +73,26 @@ function util.randomColor(color)
|
||||
end
|
||||
|
||||
function util.getColor(color)
|
||||
if vim.o.background == "dark" then return color end
|
||||
if not util.colorCache[color] then util.colorCache[color] = util.invertColor(color) end
|
||||
if vim.o.background == "dark" then
|
||||
return color
|
||||
end
|
||||
if not util.colorCache[color] then
|
||||
util.colorCache[color] = util.invertColor(color)
|
||||
end
|
||||
return util.colorCache[color]
|
||||
end
|
||||
|
||||
-- local ns = vim.api.nvim_create_namespace("tokyonight")
|
||||
function util.highlight(group, color)
|
||||
if color.fg then util.colorsUsed[color.fg] = true end
|
||||
if color.bg then util.colorsUsed[color.bg] = true end
|
||||
if color.sp then util.colorsUsed[color.sp] = true end
|
||||
if color.fg then
|
||||
util.colorsUsed[color.fg] = true
|
||||
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 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
|
||||
util.debug(color)
|
||||
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
|
||||
@@ -111,28 +131,27 @@ end
|
||||
--- Delete the autocmds when the theme changes to something else
|
||||
function util.onColorScheme()
|
||||
if vim.g.colors_name ~= "tokyonight" then
|
||||
vim.cmd [[autocmd! TokyoNight]]
|
||||
vim.cmd [[augroup! TokyoNight]]
|
||||
vim.cmd([[autocmd! TokyoNight]])
|
||||
vim.cmd([[augroup! TokyoNight]])
|
||||
end
|
||||
end
|
||||
|
||||
---@param config Config
|
||||
function util.autocmds(config)
|
||||
vim.cmd [[augroup TokyoNight]]
|
||||
vim.cmd [[ autocmd!]]
|
||||
vim.cmd [[ autocmd ColorScheme * lua require("tokyonight.util").onColorScheme()]]
|
||||
vim.cmd([[augroup TokyoNight]])
|
||||
vim.cmd([[ autocmd!]])
|
||||
vim.cmd([[ autocmd ColorScheme * lua require("tokyonight.util").onColorScheme()]])
|
||||
if config.dev then
|
||||
vim.cmd [[ autocmd BufWritePost */lua/tokyonight/** nested colorscheme tokyonight]]
|
||||
vim.cmd([[ autocmd BufWritePost */lua/tokyonight/** nested colorscheme tokyonight]])
|
||||
end
|
||||
for _, sidebar in ipairs(config.sidebars) do
|
||||
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
|
||||
vim.cmd([[ autocmd FileType ]] .. sidebar ..
|
||||
[[ setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]])
|
||||
vim.cmd([[ autocmd FileType ]] .. sidebar .. [[ setlocal winhighlight=Normal:NormalSB,SignColumn:SignColumnSB]])
|
||||
end
|
||||
end
|
||||
vim.cmd [[augroup end]]
|
||||
vim.cmd([[augroup end]])
|
||||
end
|
||||
|
||||
-- Simple string interpolation.
|
||||
@@ -142,10 +161,16 @@ end
|
||||
---@param str string template string
|
||||
---@param table table key value pairs to replace in the string
|
||||
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
|
||||
|
||||
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
|
||||
function util.terminal(colors)
|
||||
@@ -184,16 +209,22 @@ function util.terminal(colors)
|
||||
end
|
||||
|
||||
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 = {}
|
||||
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
|
||||
end
|
||||
|
||||
---@param theme Theme
|
||||
function util.load(theme)
|
||||
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.g.colors_name = "tokyonight"
|
||||
@@ -214,13 +245,17 @@ end
|
||||
function util.color_overrides(colors, config)
|
||||
if type(config.colors) == "table" then
|
||||
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
|
||||
-- hex override
|
||||
colors[key] = value
|
||||
else
|
||||
-- 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]
|
||||
end
|
||||
end
|
||||
@@ -234,13 +269,17 @@ function util.light(brightness)
|
||||
if type(hl[key]) == "number" then
|
||||
local hex = string.format("#%06x", hl[key])
|
||||
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)
|
||||
end
|
||||
end
|
||||
if hl_name ~= "" and #def > 0 then
|
||||
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
|
||||
|
||||
vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " "))
|
||||
@@ -262,7 +301,9 @@ function util.random()
|
||||
end
|
||||
if hl_name ~= "" and #def > 0 then
|
||||
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
|
||||
|
||||
vim.cmd("highlight! " .. hl_name .. " " .. table.concat(def, " "))
|
||||
@@ -271,4 +312,3 @@ function util.random()
|
||||
end
|
||||
|
||||
return util
|
||||
|
||||
|
||||
1
selene.toml
Normal file
1
selene.toml
Normal file
@@ -0,0 +1 @@
|
||||
std="lua51+vim"
|
||||
3
stylua.toml
Normal file
3
stylua.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
indent_type = "Spaces"
|
||||
indent_width = 2
|
||||
column_width = 120
|
||||
Reference in New Issue
Block a user