Skip to content

Commit

Permalink
Merge pull request #122 from ful1e5/main
Browse files Browse the repository at this point in the history
refactor: colorscheme exports
  • Loading branch information
ful1e5 authored Oct 22, 2021
2 parents f3b6133 + a77e5d5 commit 6c2bfa3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Github's default themes for `tmux`
- plugin support: nvim-compe, nvim-cmp and nvim-notify
- set `vim.o.background` while loading individual colorscheme (folke/tokyonight.nvim#102)
- enhance: assign config default value to `vim.g` variables
- re-patch: #72
- breaking change: `github` deprecated from `colorscheme` command

### Fixes

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ colorscheme github_dark
```lua
-- Example config in Lua
require("github-theme").setup({
functionStyle = "italic",
theme_style = "dark",
function_style = "italic",
sidebars = {"qf", "vista_kind", "terminal", "packer"},

-- Change the "hint" color to the "orange" color, and make the "error" color bright red
Expand Down
9 changes: 0 additions & 9 deletions colors/github.lua

This file was deleted.

1 change: 1 addition & 0 deletions lua/github-theme/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vim = vim or {g = {}, o = {}}
local function opt(key, default)
key = "github_" .. key
if vim.g[key] == nil then
vim.g[key] = default
return default
else
if vim.g[key] == 1 then
Expand Down
23 changes: 10 additions & 13 deletions lua/github-theme/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local hsluv = require("github-theme.hsluv")

local util = {}

util.colors_name = ""
util.colorsUsed = {}
util.colorCache = {}

Expand Down Expand Up @@ -118,19 +119,20 @@ end

--- Delete the autocmds when the theme changes to something else
function util.onColorScheme()
if vim.g.colors_name ~= "github" then
vim.cmd([[autocmd! github]])
vim.cmd([[augroup! github]])
if vim.g.colors_name ~= util.colors_name then
vim.cmd("autocmd! " .. util.colors_name)
vim.cmd("augroup!" .. util.colors_name)
end
end

---@param config Config
function util.autocmds(config)
vim.cmd([[augroup github]])
vim.cmd("augroup " .. util.colors_name)
vim.cmd([[ autocmd!]])
vim.cmd([[ autocmd ColorScheme * lua require("github-theme.util").onColorScheme()]])
if config.dev then
vim.cmd([[ autocmd BufWritePost */lua/github-theme/** nested colorscheme github]])
vim.cmd(" autocmd BufWritePost */lua/github-theme/** nested colorscheme " ..
util.colors_name)
end
for _, sidebar in ipairs(config.sidebars) do
if sidebar == "terminal" then
Expand Down Expand Up @@ -196,20 +198,15 @@ function util.terminal(colors)
end
end

function util.light_colors(colors)
if type(colors) == "string" then return util.getColor(colors) end
local ret = {}
for key, value in pairs(colors) do ret[key] = util.light_colors(value) end
return ret
end

---@param theme Theme
function util.load(theme)
vim.cmd("hi clear")
if vim.fn.exists("syntax_on") then vim.cmd("syntax reset") end

util.colors_name = "github_" .. vim.g.github_theme_style

vim.o.termguicolors = true
vim.g.colors_name = "github"
vim.g.colors_name = util.colors_name
-- vim.api.nvim__set_hl_ns(ns)

-- load base theme
Expand Down

0 comments on commit 6c2bfa3

Please sign in to comment.