Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: proper color docs with gt.Palette type #155

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- define global in project `luarc` config file.
- Removed unnecessary defer function & highlights
- allow customizing highlight group ful1e5/onedark.nvim#91
- Refactor: Colors moved to `palette` module
- refactor: Colors moved to `palette` module
- `types` module initiate
- proper color docs with `gt.Palette` type

### Fixes

- dark foreground color for visited entries in telescope.nvim
- Fix #144 - Repatch removed hop.nvim highlights
- Fix #133 - highlights of inactive tabline in lualine plugin
- inherit `eof` color from `fg_gutter` #150
- cleanup: _getColor()_ from `util` module

## [v0.0.3] - 09 Dec 2021

Expand Down
5 changes: 2 additions & 3 deletions lua/github-theme/colors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ local config_module = require("github-theme.config")
local M = {}

---@param config github-theme.Config
---@return github-theme.ColorScheme
---@return gt.Palette
function M.setup(config)
config = config or config_module.config

-- Color Palette
---@class github-theme.ColorScheme
---@type gt.Palette
local colors = require("github-theme.palette")(config.theme_style)

-- useful for 'util.darken()' and 'util.lighten()'
Expand Down
97 changes: 95 additions & 2 deletions lua/github-theme/types/gt.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,100 @@
local gt = {}

---@class gt.ColorGroup table<string, string>
---@class gt.Palette table<string, string|gt.ColorGroup>
---@class gt.HexColor string

---@class gt.PMenuPalette
---@field bg gt.HexColor
---@field sbar gt.HexColor

---@class gt.GitPalette
---@field add gt.HexColor
---@field change gt.HexColor
---@field delete gt.HexColor
---@field conflict gt.HexColor
---@field ignore gt.HexColor
---@field renamed gt.HexColor

---@class gt.DiffPalette
---@field add gt.HexColor
---@field add_fg gt.HexColor
---@field change gt.HexColor
---@field change_fg gt.HexColor
---@field delete gt.HexColor
---@field delete_fg gt.HexColor

---@class gt.SyntaxPalette
---@field comment gt.HexColor
---@field constant gt.HexColor
---@field string gt.HexColor
---@field variable gt.HexColor
---@field keyword gt.HexColor
---@field func gt.HexColor
---@field func_param gt.HexColor
---@field match_paren_bg gt.HexColor
---@field tag gt.HexColor
---@field html_arg gt.HexColor
---@field param gt.HexColor
---@field json_label gt.HexColor

---@class gt.GitSignPalette
---@field add gt.HexColor
---@field change gt.HexColor
---@field delete gt.HexColor

---@class gt.Palette
---Background Colors
---@field bg gt.HexColor
---@field bg2 gt.HexColor
---Foreground Colors
---@field fg gt.HexColor
---@field fg_dark gt.HexColor
---@field fg_gutter gt.HexColor
---@field fg_light gt.HexColor
---@field term_fg gt.HexColor
---Background Highlights Colors
---@field bg_highlight gt.HexColor
---@field bg_search gt.HexColor
---@field bg_visual gt.HexColor
---@field bg_visual_selection gt.HexColor
---@field border gt.HexColor
---Cursor & LineNumber Colors
---@field cursor gt.HexColor
---@field cursor_line_nr gt.HexColor
---@field line_nr gt.HexColor
---LSP & Diagnostic Colors
---@field error gt.HexColor
---@field warning gt.HexColor
---@field info gt.HexColor
---@field hint gt.HexColor
---@field lsp gt.HexColor
---DropDown Menu Colors
---@field pmenu gt.PMenuPalette
---Git Colors
---@field git gt.GitPalette
---Git-Diff Colors
---@field diff gt.DiffPalette
---Syntax Related Colors
---@field syntax gt.SyntaxPalette
---Terminal Colors
---@field orange gt.HexColor
---@field black gt.HexColor
---@field bright_black gt.HexColor
---@field white gt.HexColor
---@field bright_white gt.HexColor
---@field red gt.HexColor
---@field bright_red gt.HexColor
---@field green gt.HexColor
---@field bright_green gt.HexColor
---@field yellow gt.HexColor
---@field bright_yellow gt.HexColor
---@field blue gt.HexColor
---@field bright_blue gt.HexColor
---@field magenta gt.HexColor
---@field bright_magenta gt.HexColor
---@field cyan gt.HexColor
---@field bright_cyan gt.HexColor
---GitSign Plugin Colors
---@field git_signs gt.GitSignPalette

---@alias gt.ThemeStyle "'dark'" | "'dark_default'" | "'dimmed'" | "'light'" | "'light_default'"
gt.ThemeStyle = {}
Expand Down
27 changes: 7 additions & 20 deletions lua/github-theme/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ local function hexToRgb(hex_str)
return {tonumber(r, 16), tonumber(g, 16), tonumber(b, 16)}
end

---@param fg string foreground color
---@param bg string background color
---@param fg gt.HexColor foreground color
---@param bg gt.HexColor background color
---@param alpha number number between 0 and 1. 0 results in bg, 1 results in fg
function util.blend(fg, bg, alpha)
bg = hexToRgb(bg)
Expand Down Expand Up @@ -70,23 +70,16 @@ function util.randomColor(color)
return color
end

function util.getColor(color)
if vim.o.background == "dark" then return color end
if vim.o.background == "light" then return color end
if not util.colorCache[color] then util.colorCache[color] = util.invertColor(color) end
return util.colorCache[color]
end

-- local ns = vim.api.nvim_create_namespace("github-theme")
function util.highlight(group, color)
if color.fg then util.colorsUsed[color.fg] = true end
if color.bg then util.colorsUsed[color.bg] = true end
if color.sp then util.colorsUsed[color.sp] = true end

local style = color.style and "gui=" .. color.style or "gui=NONE"
local fg = color.fg and "guifg=" .. util.getColor(color.fg) or "guifg=NONE"
local bg = color.bg and "guibg=" .. util.getColor(color.bg) or "guibg=NONE"
local sp = color.sp and "guisp=" .. util.getColor(color.sp) or ""
local fg = color.fg and "guifg=" .. color.fg or "guifg=NONE"
local bg = color.bg and "guibg=" .. color.bg or "guibg=NONE"
local sp = color.sp and "guisp=" .. color.sp or ""

local hl = "highlight " .. group .. " " .. style .. " " .. fg .. " " .. bg .. " " .. sp

Expand Down Expand Up @@ -162,7 +155,7 @@ function util.syntax(syntax)
for group, colors in pairs(syntax) do util.highlight(group, colors) end
end

---@param colors github-theme.ColorScheme
---@param colors gt.Palette
function util.terminal(colors)
-- dark
vim.g.terminal_color_0 = colors.black
Expand Down Expand Up @@ -190,12 +183,6 @@ function util.terminal(colors)

vim.g.terminal_color_6 = colors.cyan
vim.g.terminal_color_14 = colors.bright_cyan

if vim.o.background == "light" then
for i = 0, 15, 1 do
vim.g["terminal_color_" .. i] = util.getColor(vim.g["terminal_color_" .. i])
end
end
end

---Override custom highlights in `group`
Expand Down Expand Up @@ -224,7 +211,7 @@ function util.load(theme)
util.syntax(theme.plugins)
end

---@param colors github-theme.ColorScheme
---@param colors gt.Palette
---@param config github-theme.Config
function util.color_overrides(colors, config)
if type(config.colors) == "table" then
Expand Down