Skip to content

Commit

Permalink
fix(config): options.darken.floats is not used
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmillr committed Jul 11, 2024
1 parent 6829ce3 commit 6970f32
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lua/github-theme/_test/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lua/github-theme/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local defaults = {
search = false,
},
darken = {
floats = false,
floats = true,
sidebars = {
enable = true,
list = {},
Expand Down
2 changes: 1 addition & 1 deletion lua/github-theme/group/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 44 additions & 0 deletions test/github-theme/config/darken_spec.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6970f32

Please sign in to comment.