From 4c05b1de9fed0b68d958964dddafa69df92dcfe5 Mon Sep 17 00:00:00 2001 From: siduck Date: Wed, 1 Jun 2022 19:34:00 +0530 Subject: [PATCH] add transparency toggler function | https://github.com/NvChad/NvChad/issues/1161 --- lua/base46.lua | 45 +++++++++++++++++++++++++++++++++++---------- lua/chadlights.lua | 2 +- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/lua/base46.lua b/lua/base46.lua index b93a053..c2c46a3 100644 --- a/lua/base46.lua +++ b/lua/base46.lua @@ -1,4 +1,5 @@ local M = {} +local g = vim.g local config = require("core.utils").load_config() M.get_theme_tb = function(name, type) @@ -18,7 +19,7 @@ M.get_theme_tb = function(name, type) end M.get_colors = function(type) - local name = vim.g.nvchad_theme + local name = g.nvchad_theme return M.get_theme_tb(name, type) end @@ -42,7 +43,7 @@ end M.load_theme = function() -- 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 M.clear_highlights "BufferLine" @@ -72,21 +73,21 @@ M.toggle_theme = function() local theme1 = themes[1] local theme2 = themes[2] - if vim.g.nvchad_theme == theme1 or vim.g.nvchad_theme == theme2 then - if vim.g.toggle_theme_icon == "  " then - vim.g.toggle_theme_icon = "  " + if g.nvchad_theme == theme1 or g.nvchad_theme == theme2 then + if g.toggle_theme_icon == "  " then + g.toggle_theme_icon = "  " else - vim.g.toggle_theme_icon = "  " + g.toggle_theme_icon = "  " end end - if vim.g.nvchad_theme == theme1 then - vim.g.nvchad_theme = theme2 + if g.nvchad_theme == theme1 then + g.nvchad_theme = theme2 require("nvchad").reload_theme() require("nvchad").change_theme(theme1, theme2) - elseif vim.g.nvchad_theme == theme2 then - vim.g.nvchad_theme = theme1 + elseif g.nvchad_theme == theme2 then + g.nvchad_theme = theme1 require("nvchad").reload_theme() require("nvchad").change_theme(theme2, theme1) @@ -95,4 +96,28 @@ M.toggle_theme = function() 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 diff --git a/lua/chadlights.lua b/lua/chadlights.lua index 6897e3c..3162094 100644 --- a/lua/chadlights.lua +++ b/lua/chadlights.lua @@ -47,7 +47,7 @@ if ui.hl_override then end -- local set_transparent = nvchad.load_config().ui.transparency -if ui.transparency then +if vim.g.transparency then highlights = merge_tb(highlights, require "nv_glassy") end