martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.23k stars 256 forks source link

Get current background color and theme event #882

Closed erf closed 1 year ago

erf commented 3 years ago

Is there a way to get the background color of the current theme?

Also an event for when switching themes would be nice.

plasmoduck commented 3 years ago

I just use default-16.lua theme and that uses my terminal colors which are gruvbox modified.

erf commented 3 years ago

Oh, I meant via the Lua api

moesasji commented 3 years ago

I think that the way this is done by vis-seapeak might be what you are looking for?

erf commented 3 years ago

I was more looking for a way to get the current background color or an event when when the theme was set, with the theme colors so i could get it from there.

erf commented 3 years ago

.. but what vis-seapeak has done, gave me an idea, of how to add themes as plugins !

That is by adding a separate init.lua file and calling set_theme on the INIT event, you could easily add themes as plugins, e.g. using my vis-plug - shameless plug ;)

parazyd commented 3 years ago

My way of solving this is something like the following:

.visrc:

background = 'dark'
vis:command_register("tbg", function()
    if background == 'light' then
        background = 'dark'
    else if background == 'dark' then
        background = 'light'
    end
end)

vis:command('map! normal <F12> :tbg<Enter>:set\\ theme\\ gruvbox<Enter>')

And I modified the gruvbox theme to use the background variable.

local mode = background