Something went wrong. Try again.
jujutsu file annotations for neovim (like blame)
Something went wrong. Try again.
2.9 kB · 110 lines
Lua
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111local M = {}
local GOLDEN_RATIO_CONJUGATE = 0.618033988749895
--- This is totally not AI generated and I definitely know what this all means, trust me bro!---@param str string---@return numberlocal function hash(str) local h = 2166136261 for i = 1, #str do h = bit.bxor(h, string.byte(str, i)) h = (h * 16777619) % 2 ^ 32 end return hend
---@param hue number---@param sat number---@param light number---@return stringlocal function hsl_to_hex(hue, sat, light) local h = hue / 60 local c = (1 - math.abs(2 * light - 1)) * sat local x = c * (1 - math.abs(h % 2 - 1)) local m = light - c / 2
local r, g, b if h < 1 then r, g, b = c, x, 0 elseif h < 2 then r, g, b = x, c, 0 elseif h < 3 then r, g, b = 0, c, x elseif h < 4 then r, g, b = 0, x, c elseif h < 5 then r, g, b = x, 0, c else r, g, b = c, 0, x end
return string.format( "#%02x%02x%02x", math.floor((r + m) * 255), math.floor((g + m) * 255), math.floor((b + m) * 255) )end
--- Returns a stable "golden ratio" color from a given string, in hex format.---@param str string---@param sat number---@param light number---@return stringfunction M.stable_from_string(str, sat, light) local hue = ((hash(str) * GOLDEN_RATIO_CONJUGATE) % 1) * 360 return hsl_to_hex(hue, sat, light)end
---@type jjannotate.Config.ResolvedPalettelocal palette_dark = { fg = { sat = 0.6, light = 0.7 }, fg_bold = { sat = 0.75, light = 0.75 }, bg = { sat = 0.25, light = 0.125 },}
---@type jjannotate.Config.ResolvedPalettelocal palette_light = { fg = { sat = 0.35, light = 0.35 }, fg_bold = { sat = 0.5, light = 0.3 }, bg = { sat = 0.25, light = 0.925 },}
M.palette_dark = palette_darkM.palette_light = palette_light
---@param x number---@param min number---@param max number---@return numberlocal function clamp(x, min, max) return math.min(math.max(x, min), max) end
---@param base jjannotate.Config.ResolvedPalette---@param multiplier jjannotate.Config.Palette.Color---@return jjannotate.Config.ResolvedPalettelocal function apply_multiplier(base, multiplier) return vim.tbl_map( function(color) return { sat = clamp(color.sat * multiplier.sat, 0, 1), light = clamp(color.light * multiplier.light, 0, 1), } end, base ) --[[@as jjannotate.Config.ResolvedPalette]]end
---@param palette jjannotate.Config.Palette---@return jjannotate.Config.ResolvedPalettefunction M.resolve_palette(palette) if palette == "auto" then return vim.o.background == "dark" and palette_dark or palette_light end if palette.auto then local base = vim.o.background == "dark" and palette_dark or palette_light local m = palette.multiplier or { sat = 1, light = 1 } return apply_multiplier(base, m) end return palette --[[@as jjannotate.Config.ResolvedPalette]]end
return M