Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
soulfresh authored and siduck committed Aug 22, 2024
1 parent 9dfb55a commit 0dc134f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
32 changes: 32 additions & 0 deletions lua/base46/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,36 @@ M.hex2complementary = function(hex, count)
return complementary_colors
end

-- Mix two colors with a given percentage.
-- @param first The primary hex color.
-- @param second The hex color you want to mix into the first color.
-- @param strength The percentage of second color in the output.
-- This needs to be a number between 0 - 100.
-- @return The mixed color as a hex value
M.mix = function(first, second, strength)
if strength == nil then
strength = 0.5
end

local s = strength / 100
local r1, g1, b1 = M.hex2rgb(first)
local r2, g2, b2 = M.hex2rgb(second)

if r1 == nil or r2 == nil then
return first
end

if s == 0 then
return first
elseif s == 1 then
return second
end

local r3 = r1 * (1 - s) + r2 * s
local g3 = g1 * (1 - s) + g2 * s
local b3 = b1 * (1 - s) + b2 * s

return M.rgb2hex(r3, g3, b3)
end

return M
15 changes: 12 additions & 3 deletions lua/base46/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ M.merge_tb = function(...)
return vim.tbl_deep_extend("force", ...)
end

local change_hex_lightness = require("base46.colors").change_hex_lightness
local lighten = require("base46.colors").change_hex_lightness
local mixcolors = require("base46.colors").mix

-- turns color var names in hl_override/hl_add to actual colors
-- hl_add = { abc = { bg = "one_bg" }} -> bg = colors.one_bg
Expand All @@ -55,9 +56,17 @@ M.turn_str_to_color = function(tb)

for _, hlgroups in pairs(copy) do
for opt, val in pairs(hlgroups) do
local valtype = type(val)

if opt == "fg" or opt == "bg" or opt == "sp" then
if not (type(val) == "string" and val:sub(1, 1) == "#" or val == "none" or val == "NONE") then
hlgroups[opt] = type(val) == "table" and change_hex_lightness(colors[val[1]], val[2]) or colors[val]
-- named colors from base30
if valtype == "string" and val:sub(1, 1) ~= "#" and val ~= "none" and val ~= "NONE" then
hlgroups[opt] = colors[val]
elseif valtype == "table" then

-- transform table to color
hlgroups[opt] = #val == 2 and lighten(colors[val[1]], val[2])
or mixcolors(colors[val[1]], colors[val[2]], val[3])
end
end
end
Expand Down

0 comments on commit 0dc134f

Please sign in to comment.