mirror of
https://github.com/gabehf/base46.git
synced 2026-03-14 09:46:00 -07:00
add transparency toggler function | https://github.com/NvChad/NvChad/issues/1161
This commit is contained in:
parent
1a4e761b8a
commit
4c05b1de9f
2 changed files with 36 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
local g = vim.g
|
||||||
local config = require("core.utils").load_config()
|
local config = require("core.utils").load_config()
|
||||||
|
|
||||||
M.get_theme_tb = function(name, type)
|
M.get_theme_tb = function(name, type)
|
||||||
|
|
@ -18,7 +19,7 @@ M.get_theme_tb = function(name, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
M.get_colors = function(type)
|
M.get_colors = function(type)
|
||||||
local name = vim.g.nvchad_theme
|
local name = g.nvchad_theme
|
||||||
return M.get_theme_tb(name, type)
|
return M.get_theme_tb(name, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -42,7 +43,7 @@ end
|
||||||
|
|
||||||
M.load_theme = function()
|
M.load_theme = function()
|
||||||
-- set bg option
|
-- set bg option
|
||||||
local theme_type = M.get_theme_tb(vim.g.nvchad_theme, "type") -- dark/light
|
local theme_type = M.get_theme_tb(g.nvchad_theme, "type") -- dark/light
|
||||||
vim.opt.bg = theme_type
|
vim.opt.bg = theme_type
|
||||||
|
|
||||||
M.clear_highlights "BufferLine"
|
M.clear_highlights "BufferLine"
|
||||||
|
|
@ -72,21 +73,21 @@ M.toggle_theme = function()
|
||||||
local theme1 = themes[1]
|
local theme1 = themes[1]
|
||||||
local theme2 = themes[2]
|
local theme2 = themes[2]
|
||||||
|
|
||||||
if vim.g.nvchad_theme == theme1 or vim.g.nvchad_theme == theme2 then
|
if g.nvchad_theme == theme1 or g.nvchad_theme == theme2 then
|
||||||
if vim.g.toggle_theme_icon == " " then
|
if g.toggle_theme_icon == " " then
|
||||||
vim.g.toggle_theme_icon = " "
|
g.toggle_theme_icon = " "
|
||||||
else
|
else
|
||||||
vim.g.toggle_theme_icon = " "
|
g.toggle_theme_icon = " "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.g.nvchad_theme == theme1 then
|
if g.nvchad_theme == theme1 then
|
||||||
vim.g.nvchad_theme = theme2
|
g.nvchad_theme = theme2
|
||||||
|
|
||||||
require("nvchad").reload_theme()
|
require("nvchad").reload_theme()
|
||||||
require("nvchad").change_theme(theme1, theme2)
|
require("nvchad").change_theme(theme1, theme2)
|
||||||
elseif vim.g.nvchad_theme == theme2 then
|
elseif g.nvchad_theme == theme2 then
|
||||||
vim.g.nvchad_theme = theme1
|
g.nvchad_theme = theme1
|
||||||
|
|
||||||
require("nvchad").reload_theme()
|
require("nvchad").reload_theme()
|
||||||
require("nvchad").change_theme(theme2, theme1)
|
require("nvchad").change_theme(theme2, theme1)
|
||||||
|
|
@ -95,4 +96,28 @@ M.toggle_theme = function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.toggle_transparency = function()
|
||||||
|
local transparency_status = require("core.utils").load_config().ui.transparency
|
||||||
|
local write_data = require("nvchad").write_data
|
||||||
|
|
||||||
|
local function save_chadrc_data()
|
||||||
|
local old_data = "transparency = " .. tostring(transparency_status)
|
||||||
|
local new_data = "transparency = " .. tostring(g.transparency)
|
||||||
|
|
||||||
|
write_data(old_data, new_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
if g.transparency then
|
||||||
|
g.transparency = false
|
||||||
|
|
||||||
|
M.load_theme()
|
||||||
|
save_chadrc_data()
|
||||||
|
else
|
||||||
|
g.transparency = true
|
||||||
|
|
||||||
|
M.load_theme()
|
||||||
|
save_chadrc_data()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ if ui.hl_override then
|
||||||
end
|
end
|
||||||
|
|
||||||
-- local set_transparent = nvchad.load_config().ui.transparency
|
-- local set_transparent = nvchad.load_config().ui.transparency
|
||||||
if ui.transparency then
|
if vim.g.transparency then
|
||||||
highlights = merge_tb(highlights, require "nv_glassy")
|
highlights = merge_tb(highlights, require "nv_glassy")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue