vis: update theme on C-l but only if file changed and theme changed dark<->light

This commit is contained in:
2025-09-26 23:11:21 +02:00
parent 1449ff5d5c
commit e6cb4df579

View File

@@ -189,12 +189,27 @@ local function add_global_mark()
end
end
local lfs = require('lfs')
local theme_modification = 0
local last_theme = 'default'
function set_current_theme()
local f = io.open(os.getenv('HOME') .. '/.config/xsettingsd/xsettingsd.conf')
local path = os.getenv('HOME') .. '/.config/xsettingsd/xsettingsd.conf'
local m = lfs.attributes(path, 'modification')
if m == theme_modification then
return
end
theme_modification = m
local f = io.open(path)
if f then
local s = f:read('*all')
f:close()
if s:match('light') then
local theme = s:match('light') and 'light' or 'dark'
if theme == last_theme then
return
end
last_theme = theme
if theme == 'light' then
vis:command('set theme lupan-light')
else
vis:command('set theme lupan-dark')
@@ -349,7 +364,11 @@ vis.events.subscribe(vis.events.INIT, function()
vis:map(vis.modes.NORMAL, ' tl', function()
vis:command('set theme lupan-light')
end, 'change to light theme')
vis:map(vis.modes.NORMAL, ' tt', set_current_theme)
vis:map(vis.modes.NORMAL, '<C-l>', function()
vis:feedkeys('<vis-selections-remove-column-except>')
set_current_theme()
end, 'Remove all but the count selection column and update theme if needed')
set_current_theme()
end)