summaryrefslogtreecommitdiff
path: root/lua/mo/zen.lua
blob: eb674ba6d123f575b62cc7eac91975b739e5d302 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
local M = {}
M.themes = {
    dark = {
        "seoulbones",
        "rosebones",
        "forestbones",
        "zenwritten",
    },
    light = {
        "seoulbones",
        "vimbones",
        "rosebones",
        "forestbones",
    },
}
M.current = {
    dark = 1,
    light = 1,
}
M.bg = "dark"

M.cycle = function()
    M.current[M.bg] = M.current[M.bg] + 1
    if M.current[M.bg] > #M.themes[M.bg] then M.current[M.bg] = 1 end
    M.set()
end

M.set = function()
    vim.o.background = M.bg
    local theme = M.themes[M.bg][M.current[M.bg]]
    vim.print("Switching to " .. theme)

    vim.g[theme .. "_compat"] = 1
    vim.cmd.colorscheme(theme)

    -- make strings nonitalic
    local str_highlight =
        vim.api.nvim_get_hl(0, { name = "String", link = false })
    vim.api.nvim_set_hl(
        0,
        "String",
        { fg = str_highlight.fg, italic = false, force = true }
    )

    -- make booleans nonitalic and bold
    local bool_highlight =
        vim.api.nvim_get_hl(0, { name = "Boolean", link = false })
    vim.api.nvim_set_hl(
        0,
        "Boolean",
        { fg = bool_highlight.fg, italic = false, bold = true, force = true }
    )

    -- make normals in seoulbones darker
    if theme == "seoulbones" and M.bg == "dark" then
        local norm_highlight =
            vim.api.nvim_get_hl(0, { name = "Normal", link = false })
        vim.api.nvim_set_hl(
            0,
            "Normal",
            { fg = norm_highlight.fg, bg = "#313131", force = true }
        )
    end
end

M.togglebg = function()
    M.bg = M.bg == "dark" and "light" or "dark"
    M.set()
end

---@param theme string?
---@param bg "dark"|"light"|nil
M.setup = function(theme, bg)
    vim.cmd("packadd zenbones.nvim")
    if bg then M.bg = bg end
    if theme then
        for i, th in ipairs(M.themes[M.bg]) do
            if th == theme then
                M.current[M.bg] = i
                break
            end
        end
    end
    M.set()
    vim.keymap.set("n", "<F3>", M.cycle, {})
    vim.keymap.set("n", "<F12>", M.togglebg, {})
end

return M