|
1 |
| -local collect = require('github-theme.lib.collect') |
2 |
| -local config = require('github-theme.config') |
3 |
| - |
4 | 1 | local M = {}
|
5 | 2 |
|
| 3 | +---@enum GhTheme.Theme |
6 | 4 | M.themes = {
|
7 |
| - 'github_dark', |
8 |
| - 'github_dark_colorblind', |
9 |
| - 'github_dark_default', |
10 |
| - 'github_dark_dimmed', |
11 |
| - 'github_dark_high_contrast', |
12 |
| - 'github_dark_tritanopia', |
13 |
| - 'github_light', |
14 |
| - 'github_light_colorblind', |
15 |
| - 'github_light_default', |
16 |
| - 'github_light_high_contrast', |
17 |
| - 'github_light_tritanopia', |
| 5 | + github_dark = 'github_dark', |
| 6 | + github_dark_colorblind = 'github_dark_colorblind', |
| 7 | + github_dark_default = 'github_dark_default', |
| 8 | + github_dark_dimmed = 'github_dark_dimmed', |
| 9 | + github_dark_high_contrast = 'github_dark_high_contrast', |
| 10 | + github_dark_tritanopia = 'github_dark_tritanopia', |
| 11 | + github_light = 'github_light', |
| 12 | + github_light_colorblind = 'github_light_colorblind', |
| 13 | + github_light_default = 'github_light_default', |
| 14 | + github_light_high_contrast = 'github_light_high_contrast', |
| 15 | + github_light_tritanopia = 'github_light_tritanopia', |
18 | 16 | }
|
19 | 17 |
|
20 |
| -local function override(color, ovr) |
21 |
| - for key, value in pairs(ovr) do |
22 |
| - color[key] = value |
23 |
| - end |
24 |
| - return color |
25 |
| -end |
26 |
| - |
27 |
| -function M.load(name) |
| 18 | +---@param theme GhTheme.Theme |
| 19 | +local function get_palette(theme) |
28 | 20 | local ovr = require('github-theme.override').palettes
|
29 |
| - |
30 |
| - local function apply_ovr(key, palette) |
31 |
| - return ovr[key] and override(palette, ovr[key]) or palette |
| 21 | + local raw = require('github-theme.palette.' .. theme) |
| 22 | + local pal = raw.palette |
| 23 | + if ovr.all then |
| 24 | + pal = vim.tbl_deep_extend('force', pal, ovr.all) |
32 | 25 | end
|
| 26 | + if ovr[theme] then |
| 27 | + pal = vim.tbl_deep_extend('force', pal, ovr[theme]) |
| 28 | + end |
| 29 | + pal.meta, pal.generate_spec = raw.meta, raw.generate_spec |
| 30 | + return pal |
| 31 | +end |
33 | 32 |
|
34 |
| - if name then |
35 |
| - local valid = collect.contains(M.themes, name) |
36 |
| - local raw = valid and require('github-theme.palette.' .. name) |
37 |
| - or require('github-theme.palette.' .. config.theme) |
38 |
| - local palette = raw.palette |
39 |
| - palette = apply_ovr('all', palette) |
40 |
| - palette = apply_ovr(name, palette) |
41 |
| - palette.meta = raw.meta |
42 |
| - palette.generate_spec = raw.generate_spec |
| 33 | +---Returns the palette for the given `theme`, or all themes (i.e. a map from |
| 34 | +---theme name to palette) if `theme` is `nil`. |
| 35 | +---@param theme? GhTheme.Theme |
| 36 | +function M.load(theme) |
| 37 | + if theme ~= nil then |
| 38 | + if not M.themes[theme] then |
| 39 | + error('invalid theme provided: ' .. theme) |
| 40 | + end |
43 | 41 |
|
44 |
| - return palette |
| 42 | + return get_palette(theme) |
45 | 43 | else
|
46 |
| - local result = {} |
47 |
| - for _, mod in ipairs(M.themes) do |
48 |
| - local raw = require('github-theme.palette.' .. mod) |
49 |
| - local palette = raw.palette |
50 |
| - palette = apply_ovr('all', palette) |
51 |
| - palette = apply_ovr(mod, palette) |
52 |
| - palette.meta = raw.meta |
53 |
| - palette.generate_spec = raw.generate_spec |
54 |
| - result[mod] = palette |
| 44 | + local all = {} |
| 45 | + |
| 46 | + ---@diagnostic disable-next-line: redefined-local |
| 47 | + for theme in pairs(M.themes) do |
| 48 | + all[theme] = get_palette(theme) |
55 | 49 | end
|
56 | 50 |
|
57 |
| - return result |
| 51 | + return all |
58 | 52 | end
|
59 | 53 | end
|
60 | 54 |
|
|
0 commit comments