Refactor colorscheme updating

Also add a util for plugin load checks
This commit is contained in:
ViViDboarder 2021-09-16 13:32:29 -07:00
parent 9bbe68013b
commit 7afc5f9903
5 changed files with 46 additions and 48 deletions

View File

@ -1,4 +1,3 @@
-- luacheck: globals packer_plugins
local utils = require("utils") local utils = require("utils")
local map = vim.api.nvim_set_keymap local map = vim.api.nvim_set_keymap
@ -48,9 +47,9 @@ map("v", "``", "<esc>", opt_default)
function _G.complete_space() function _G.complete_space()
if vim.fn.pumvisible() == 1 then if vim.fn.pumvisible() == 1 then
return utils.t("<C-n>") return utils.t("<C-n>")
elseif packer_plugins["completion-nvim"] and packer_plugins["completion-nvim"].loaded then elseif utils.is_plugin_loaded("completion-nvim") then
return utils.t("<Plug>(completion_trigger)") return utils.t("<Plug>(completion_trigger)")
elseif packer_plugins["nvim-compe"] and packer_plugins["nvim-compe"].loaded then elseif utils.is_plugin_loaded("nvim-compe") then
return vim.fn["compe#complete"]() return vim.fn["compe#complete"]()
else else
return utils.t("<C-x><C-o>") return utils.t("<C-x><C-o>")

View File

@ -1,7 +1,4 @@
-- luacheck: globals packer_plugins -- Update colors based on environment variables
local utils = require("utils")
-- TODO: Determine if I want to keep this or remove it in favor of dark-notify
function _G.update_colors() function _G.update_colors()
local function maybe_set(scope, name, val) local function maybe_set(scope, name, val)
if vim[scope][name] ~= val then if vim[scope][name] ~= val then
@ -12,12 +9,13 @@ function _G.update_colors()
end end
-- Set colorscheme based on env -- Set colorscheme based on env
local utils = require("utils")
local default_color = "solarized" local default_color = "solarized"
local env_color = utils.env_default("VIM_COLOR", default_color) local env_color = utils.env_default("VIM_COLOR", default_color)
env_color = utils.env_default("NVIM_COLOR", env_color) env_color = utils.env_default("NVIM_COLOR", env_color)
-- Read dark mode -- Read dark mode
local mode = vim.env.IS_DARKMODE local mode = utils.env_default("IS_DARKMODE", "dark")
if vim.g.is_mac == 1 then if vim.g.is_mac == 1 then
local cmd = "defaults read -g AppleInterfaceStyle 2>/dev/null || echo Light" local cmd = "defaults read -g AppleInterfaceStyle 2>/dev/null || echo Light"
mode = vim.fn.system(cmd):gsub("\n", ""):lower() mode = vim.fn.system(cmd):gsub("\n", ""):lower()
@ -38,21 +36,26 @@ function _G.update_colors()
end end
-- Update status line theme -- Update status line theme
if change and vim.fn.exists(":AirlineRefresh") == 1 then if change then
if vim.fn.exists(":AirlineRefresh") == 1 then
vim.cmd(":AirlineRefresh") vim.cmd(":AirlineRefresh")
elseif (change and _G["packer_plugins"] elseif utils.is_plugin_loaded("lualine.nvim") then
and packer_plugins["lualine"] and packer_plugins["lualine"].loaded) then
local lualine_theme = vim.g.colors_name local lualine_theme = vim.g.colors_name
if lualine_theme == "solarized" then if lualine_theme == "solarized" then
lualine_theme = lualine_theme .. "_" .. mode lualine_theme = lualine_theme .. "_" .. mode
end end
require("plugins.lualine").config_lualine(lualine_theme) require("plugins.lualine").config_lualine(lualine_theme)
end end
end
return change and "Changed color to " .. env_color .. " with mode " .. mode or "No change" return change and "Changed color to " .. env_color .. " with mode " .. mode or "No change"
end end
-- utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()")
-- Initial set of colors -- Don't need the autocommand when dark-notify is installed
-- TODO: if update_colors() is removed, use the env color fetching and set the colorscheme here local utils = require("utils")
if not utils.is_plugin_loaded("dark-notify") then
utils.autocmd("auto_colors", "FocusGained * call v:lua.update_colors()")
end
-- Initial setting of colors
_G.update_colors() _G.update_colors()

View File

@ -1,4 +1,4 @@
-- Do all Packer stuff -- Install packer
local install_path = vim.fn.stdpath("data").."/site/pack/packer/start/packer.nvim" local install_path = vim.fn.stdpath("data").."/site/pack/packer/start/packer.nvim"
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
@ -6,24 +6,12 @@ if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.cmd "packadd packer.nvim" vim.cmd "packadd packer.nvim"
end end
-- Requires :PackerCompile for "config" to be loaded
-- Configures dark-notify to use colors from my environment -- Configures dark-notify to use colors from my environment
local function config_dark_notify() local function config_dark_notify()
local default_color = "solarized" require("dark_notify").run {
local env_color = utils.env_default("VIM_COLOR", default_color) onchange = function(_)
require("dark_notify").run{ -- Defined in _colors
schemes = { _G.update_colors()
dark = utils.env_default("VIM_COLOR_DARK", env_color),
light = utils.env_default("VIM_COLOR_LIGHT", env_color),
},
onchange = function(mode)
-- Update lualine with new colors
local lualine_theme = vim.g.colors_name
if lualine_theme == "solarized" then
lualine_theme = lualine_theme .. "_" .. mode
end
require("plugins.lualine").config_lualine(lualine_theme)
end, end,
} }
end end
@ -68,17 +56,21 @@ return require('packer').startup(function()
-- UI -- UI
use "~/workspace/ez-colors.nvim/wombat" use "~/workspace/ez-colors.nvim/wombat"
use { use "hoob3rt/lualine.nvim"
"~/workspace/wombuddy",
requires = "tjdevries/colorbuddy.vim",
}
use "vim-scripts/wombat256.vim" use "vim-scripts/wombat256.vim"
use "ishan9299/nvim-solarized-lua" use "ishan9299/nvim-solarized-lua"
use { use {
"norcalli/nvim-colorizer.lua", "norcalli/nvim-colorizer.lua",
config = function() require("colorizer").setup() end, config = function() require("colorizer").setup() end,
} }
use "folke/tokyonight.nvim" use {
"folke/tokyonight.nvim",
run = "fish -c 'echo \"set --path --prepend fish_themes_path \"(pwd)\"/extras\" > ~/.config/fish/conf.d/tokyonight.fish' || true", -- luacheck: no max line length
}
use {
"~/workspace/wombuddy",
requires = "tjdevries/colorbuddy.vim",
}
--[[ --[[
use { use {
"shaunsingh/solarized.nvim", "shaunsingh/solarized.nvim",
@ -100,11 +92,6 @@ return require('packer').startup(function()
requires = { "vim-airline/vim-airline-themes", opt = true }, requires = { "vim-airline/vim-airline-themes", opt = true },
} }
--]] --]]
use {
"hoob3rt/lualine.nvim",
-- configured by dark-notify
-- config = function() require("plugins.lualine").config_lualine("solarized") end,
}
use { use {
"cormacrelf/dark-notify", "cormacrelf/dark-notify",
-- Download latest release on install -- Download latest release on install
@ -184,7 +171,8 @@ return require('packer').startup(function()
-- Override key commands -- Override key commands
-- vim.g.fzf_action = { ['ctrl-t'] = 'tab split', ['ctrl-s'] = 'split', ['ctrl-v'] = 'vsplit', } -- vim.g.fzf_action = { ['ctrl-t'] = 'tab split', ['ctrl-s'] = 'split', ['ctrl-v'] = 'vsplit', }
-- Override git log to show authors -- Override git log to show authors
vim.g.fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h %an: %s%d %C(black)%C(bold)%cr"' -- luacheck: no max line length vim.g.fzf_commits_log_options = --graph --color=always \z
--format="%C(auto)%h %an: %s%d %C(black)%C(bold)%cr"
vim.g.fzf_preview_window = {"right:50%", "ctrl-/"} vim.g.fzf_preview_window = {"right:50%", "ctrl-/"}
@ -240,7 +228,7 @@ return require('packer').startup(function()
-- Debuging nvim config -- Debuging nvim config
use { use {
"tweekmonster/startuptime.vim", "tweekmonster/startuptime.vim",
cmd = { "StartupTime" }, cmd = {"StartupTime"},
} }
-- luacheck: pop -- luacheck: pop

View File

@ -1,4 +1,5 @@
-- TODO: Determine if keeping this -- TODO: Determine if keeping this
--[[
local function config_compe() local function config_compe()
require("compe").setup{ require("compe").setup{
enabled = true, enabled = true,
@ -14,6 +15,7 @@ local function config_compe()
}, },
} }
end end
--]]
-- TODO: Some issue with tags completion maybe compe is better? -- TODO: Some issue with tags completion maybe compe is better?
local function config_complete() local function config_complete()

View File

@ -1,4 +1,5 @@
-- Utils taken from https://github.com/zzzeyez/dots/blob/master/nvim/lua/utils.lua -- Utils taken from https://github.com/zzzeyez/dots/blob/master/nvim/lua/utils.lua
-- luacheck: globals packer_plugins
local M = {} local M = {}
-- Key mapping -- Key mapping
@ -89,4 +90,9 @@ function M.require_with_local(name)
return rmod return rmod
end end
-- Returns whether or not packer plugin is loaded
function M.is_plugin_loaded(name)
return _G["packer_plugins"] and packer_plugins[name] and packer_plugins[name].loaded
end
return M return M