summaryrefslogtreecommitdiff
path: root/runtime/lua/core/theme.lua
blob: cead212f51f23681ae7731c638302d5602840e5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
local M = {}

local function rgba(hex)
  local h = hex:gsub("#", "")
  if #h ~= 6 then
    return 0, 0, 0, 255
  end

  local r = tonumber(h:sub(1, 2), 16) or 0
  local g = tonumber(h:sub(3, 4), 16) or 0
  local b = tonumber(h:sub(5, 6), 16) or 0
  return r, g, b, 255
end

local default_map = {
  bg_top = "base00",
  bg_bottom = "base01",
  text = "base05",
  cursor = "base08",
  accent = "base09",
}

function M.apply_base16(palette, color_map)
  local map = color_map or default_map
  for editor_color, base_key in pairs(map) do
    local hex = palette[base_key]
    if hex then
      local r, g, b, a = rgba(hex)
      editor.set_theme_color(editor_color, r, g, b, a)
    end
  end
end

return M