local function get_component(hex, component) hex = hex:gsub("#", "") local num if component == "r" then num = tonumber("0x" .. hex:sub(1, 2)) / 255 elseif component == "g" then num = tonumber("0x" .. hex:sub(3, 4)) / 255 elseif component == "b" then num = tonumber("0x" .. hex:sub(5, 6)) / 255 end return string.format("%.16f", num) end local function template(str, table) return (str:gsub("($%b{})", function(w) return get_component(table[w:sub(3, -4)], w:sub(-2, -2)) end)) end local M = {} function M.generate(colors) local iterm = template([[ Ansi 0 Color Alpha Component 1 Blue Component ${black.b} Color Space sRGB Green Component ${black.g} Red Component ${black.r} Ansi 1 Color Alpha Component 1 Blue Component ${red.b} Color Space sRGB Green Component ${red.g} Red Component ${red.r} Ansi 10 Color Alpha Component 1 Blue Component ${green.b} Color Space sRGB Green Component ${green.g} Red Component ${green.r} Ansi 11 Color Alpha Component 1 Blue Component ${yellow.b} Color Space sRGB Green Component ${yellow.g} Red Component ${yellow.r} Ansi 12 Color Alpha Component 1 Blue Component ${blue.b} Color Space sRGB Green Component ${blue.g} Red Component ${blue.r} Ansi 13 Color Alpha Component 1 Blue Component ${magenta.b} Color Space sRGB Green Component ${magenta.g} Red Component ${magenta.r} Ansi 14 Color Alpha Component 1 Blue Component ${cyan.b} Color Space sRGB Green Component ${cyan.g} Red Component ${cyan.r} Ansi 15 Color Alpha Component 1 Blue Component ${fg.b} Color Space sRGB Green Component ${fg.g} Red Component ${fg.r} Ansi 2 Color Alpha Component 1 Blue Component ${green.b} Color Space sRGB Green Component ${green.g} Red Component ${green.r} Ansi 3 Color Alpha Component 1 Blue Component ${yellow.b} Color Space sRGB Green Component ${yellow.g} Red Component ${yellow.r} Ansi 4 Color Alpha Component 1 Blue Component ${blue.b} Color Space sRGB Green Component ${blue.g} Red Component ${blue.r} Ansi 5 Color Alpha Component 1 Blue Component ${magenta.b} Color Space sRGB Green Component ${magenta.g} Red Component ${magenta.r} Ansi 6 Color Alpha Component 1 Blue Component ${cyan.b} Color Space sRGB Green Component ${cyan.g} Red Component ${cyan.r} Ansi 7 Color Alpha Component 1 Blue Component ${fg_dark.b} Color Space sRGB Green Component ${fg_dark.g} Red Component ${fg_dark.r} Ansi 8 Color Alpha Component 1 Blue Component ${terminal_black.b} Color Space sRGB Green Component ${terminal_black.g} Red Component ${terminal_black.r} Ansi 9 Color Alpha Component 1 Blue Component ${red.b} Color Space sRGB Green Component ${red.g} Red Component ${red.r} Background Color Alpha Component 1 Blue Component ${bg.b} Color Space sRGB Green Component ${bg.g} Red Component ${bg.r} Badge Color Alpha Component 0.5 Blue Component 0.0 Color Space sRGB Green Component 0.1491314172744751 Red Component 1 Bold Color Alpha Component 1 Blue Component ${teal.b} Color Space sRGB Green Component ${teal.g} Red Component ${teal.r} Cursor Color Alpha Component 1 Blue Component ${fg.b} Color Space sRGB Green Component ${fg.g} Red Component ${fg.r} Cursor Guide Color Alpha Component 0.25 Blue Component ${fg.b} Color Space sRGB Green Component ${fg.g} Red Component ${fg.r} Cursor Text Color Alpha Component 1 Blue Component ${bg.b} Color Space sRGB Green Component ${bg.g} Red Component ${bg.r} Foreground Color Alpha Component 1 Blue Component ${fg.b} Color Space sRGB Green Component ${fg.g} Red Component ${fg.r} Link Color Alpha Component 1 Blue Component ${green1.b} Color Space sRGB Green Component ${green1.g} Red Component ${green1.r} Selected Text Color Alpha Component 1 Blue Component ${fg.b} Color Space sRGB Green Component ${fg.g} Red Component ${fg.r} Selection Color Alpha Component 1 Blue Component ${bg_visual.b} Color Space sRGB Green Component ${bg_visual.g} Red Component ${bg_visual.r} ]], colors ) return iterm end return M -- vim: sw=2