navarasu / onedark.nvim

One dark and light colorscheme for neovim >= 0.5.0 written in lua based on Atom's One Dark and Light theme. Additionally, it comes with 5 color variant styles
MIT License
1.61k stars 164 forks source link

Saving 'style' between neovim sessions #175

Open fbaltor opened 1 year ago

fbaltor commented 1 year ago

Hey, how could I save the current theme set by toggling between sessions? I'm really new to the Neovim lua scripting and tried to solve this with the script below, without success:

-- -- Colorscheme configurations
local get_onedark_style = function()
    if ONEDARK_STYLE == nil then
        ONEDARK_STYLE = 'dark'
    end

    if ONEDARK_STYLE == 'dark' then
        vim.o.background = 'dark'
    end

    if ONEDARK_STYLE == 'light' then
        vim.o.background = 'light'
    end

    return ONEDARK_STYLE
end

local onedark_options =  {
    style = get_onedark_style(),
    -- toggle theme style ---
    toggle_style_key = '<leader>ts', -- keybind to toggle theme style. Leave it nil to disable it, or set it to a string, for example "<leader>ts"
    toggle_style_list = {'light', 'dark'}, -- List of styles to toggle between. The possible styles are {'dark', 'darker', 'cool', 'deep', 'warm', 'warmer', 'light'}
}
require('onedark').setup(onedark_options)
require('onedark').load()

local save_onedark_style = function()
    print(ONEDARK_STYLE)
    if ONEDARK_STYLE == 'light' then
        vim.o.background = 'dark'
        ONEDARK_STYLE = 'dark'
    elseif ONEDARK_STYLE == 'dark' then
        vim.o.background = 'light'
        ONEDARK_STYLE = 'light'
    end

    vim.cmd('wsh!')
end

vim.api.nvim_create_autocmd('ColorScheme', {
  pattern = {'*'},
  callback = save_onedark_style,
})
fbaltor commented 1 year ago

This attempt was a implementation of the following idea: Screenshot from 2023-06-28 21-19-23

fbaltor commented 1 year ago

Any news on this?