From 6970f32af29e2caa1913542b89fc8c9b6a7bf46f Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Wed, 10 Jul 2024 02:29:45 -0700 Subject: [PATCH] fix(config): `options.darken.floats` is not used Problem: `options.darken.floats` isn't used anywhere and `NormalFloat` is unconditionally set to `spec.bg0` (darker background). Solution: Only set `bg` of `NormalFloat` to `bg0` if `options.darken.floats` is `true`, otherwise, set it to `bg1` (default background). Problem: Floating windows are darkened unconditionally and `options.darken.floats` appears to be documented as being `true` by default (see `options.darken` section of Usage.md), however, the actual default in `config.lua` is `false`. In README.md, the default value is properly documented as being `false`. Solution: Change the default value of `options.darken.floats` to `true`. Update the documented default to `true`. This is not a breaking change because this is currently the default behavior. --- CHANGELOG.md | 15 ++++++++ README.md | 2 +- lua/github-theme/_test/util.lua | 7 ++++ lua/github-theme/config.lua | 2 +- lua/github-theme/group/editor.lua | 2 +- test/github-theme/config/darken_spec.lua | 44 ++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 test/github-theme/config/darken_spec.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index d58c42a2..3a99b389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +### What's New? + +- Added new highlight groups for mini.nvim (#333 by @echasnovski) + +### Changes + +- Clarify `options.transparent` in README (resolves #327) + +### Issues Fix + +- Fixed `punctuation.delimiter` treesitter group nearly invisible (#329 fixed by #331) +- Closed #305 (no longer valid, fixed) +- Closed #292 (no longer valid, fixed) +- fix(config): `options.darken.floats` is not used (#345) + ## [v1.0.2] - 03 May 2023 ### What's New? diff --git a/README.md b/README.md index 8d52c714..56e9b168 100644 --- a/README.md +++ b/README.md @@ -281,7 +281,7 @@ require('github-theme').setup({ search = false, }, darken = { -- Darken floating windows and sidebar-like windows - floats = false, + floats = true, sidebars = { enabled = true, list = {}, -- Apply dark background to specific windows diff --git a/lua/github-theme/_test/util.lua b/lua/github-theme/_test/util.lua index 4d80f0de..b6267a7f 100644 --- a/lua/github-theme/_test/util.lua +++ b/lua/github-theme/_test/util.lua @@ -18,4 +18,11 @@ function M.await_VimEnter() end end +---@param group string +---@param link? boolean +---@return vim.api.keyset.hl_info +function M.get_hl(group, link) + return api.nvim_get_hl(0, { name = group, link = not not link, create = false }) +end + return M diff --git a/lua/github-theme/config.lua b/lua/github-theme/config.lua index 1c8e9b8d..67718e6d 100644 --- a/lua/github-theme/config.lua +++ b/lua/github-theme/config.lua @@ -30,7 +30,7 @@ local defaults = { search = false, }, darken = { - floats = false, + floats = true, sidebars = { enable = true, list = {}, diff --git a/lua/github-theme/group/editor.lua b/lua/github-theme/group/editor.lua index d8c2fea3..060d9234 100644 --- a/lua/github-theme/group/editor.lua +++ b/lua/github-theme/group/editor.lua @@ -62,7 +62,7 @@ function M.get(spec, config) NormalNC = { fg = spec.fg1, bg = (inactive and spec.bg0) or (trans and 'NONE') or spec.bg1 }, -- normal text in non-current windows - NormalFloat = { fg = spec.fg1, bg = spec.bg0 }, -- Normal text in floating windows. + NormalFloat = { fg = spec.fg1, bg = config.darken.floats and spec.bg0 or spec.bg1 }, -- Normal text in floating windows. FloatBorder = { fg = c.border.default }, -- TODO Pmenu = { fg = spec.fg1, bg = spec.bg0 }, -- Popup menu: normal item. PmenuSel = { bg = spec.sel1 }, -- Popup menu: selected item. diff --git a/test/github-theme/config/darken_spec.lua b/test/github-theme/config/darken_spec.lua new file mode 100644 index 00000000..b85190c7 --- /dev/null +++ b/test/github-theme/config/darken_spec.lua @@ -0,0 +1,44 @@ +local assert = require('luassert') +local t_util = require('github-theme._test.util') +local C = require('github-theme.lib.color') + +describe('config > options > darken', function() + before_each(function() + require('github-theme.config').reset() + end) + + describe('> floats', function() + for _, variant in ipairs(require('github-theme.palette').themes) do + -- TODO: see #324 + local _it = variant:find('high[-_]*contrast') and pending or it + + _it(('should be enabled by default (%s)'):format(variant), function() + require('github-theme').setup() + vim.cmd.colorscheme({ args = { variant } }) + local normal_float = t_util.get_hl('NormalFloat') + local normal = t_util.get_hl('Normal') + + assert.is_true(require('github-theme.config').options.darken.floats) + assert.are.not_equal(normal_float.bg, normal.bg) + assert( + C(('#%x'):format(normal_float.bg)):luminance() + < C(('#%x'):format(normal.bg)):luminance(), + ('expected `bg` of `NormalFloat` (#%x) to be darker than `bg` of `Normal` (#%x)'):format( + normal_float.bg, + normal.bg + ) + ) + end) + + it(('should be disabled when set to `false` (%s)'):format(variant), function() + require('github-theme').setup({ options = { darken = { floats = false } } }) + vim.cmd.colorscheme({ args = { variant } }) + local normal_float = t_util.get_hl('NormalFloat') + local normal = t_util.get_hl('Normal') + + assert.is_false(require('github-theme.config').options.darken.floats) + assert.are.equal(normal_float.bg, normal.bg) + end) + end + end) +end)