Skip to content

Commit

Permalink
fix(config): options.darken.sidebars.enabled
Browse files Browse the repository at this point in the history
Problem: `options.darken.sidebars.enabled` and
         `options.darken.sidebars.enable` both exist, but it is only one
         option. The default in `config.lua` is `enable`, but it is
         referred to as `enabled` as well (both in code and docs). It
         used to be `enable` but was renamed to `enabled`, so it is
         technically supposed to be `options.darken.sidebars.enabled` at
         this time (as of this commit's parent).

Solution: Deprecate and revert `options.darken.sidebars.enabled` back to
          `options.darken.sidebars.enable`. This brings it back in-line
          with the changelog and runtime deprecation checks. `enable` is
          also more consistent as this is what is used in other parts
          of the config (e.g. config for `modules`).

Problem: In a couple of places, `options.darken.sidebars` is checked for
         truthiness. This seems to be a typo of
         `options.darken.sidebars.enable` which is a boolean (unlike the
         former, which is a table by default and also documented as a
         table). Tables are always truthy.

Solution: Use `options.darken.sidebars.enable` instead of
          `options.darken.sidebars` in conditionals.

Reverts: fff3e20, 806903c
Fixes: #306
  • Loading branch information
tmillr committed Jul 12, 2024
1 parent da7281e commit 8541b58
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 19 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

### Configuration Deprecation and Migration

- Reverted/renamed `options.darken.sidebars.enabled` back to `options.darken.sidebars.enable` (see #343)

### What's New?

- Added new highlight groups for mini.nvim (#333 by @echasnovski)
Expand All @@ -18,10 +22,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Issues Fix

- Fixed `punctuation.delimiter` treesitter group nearly invisible (#329 fixed by #331)
- 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)
- Fixed sidebar is not darkened when configured to do so (affects neo-tree, etc.) (#306 fixed-by #343)

## [v1.0.2] - 03 May 2023

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test: $(PLENARY_DIR)
--headless \
--noplugin \
-u test/minimal_init.vim \
-c "PlenaryBustedDirectory $(TEST_DIR) { minimal_init = './test/minimal_init.vim' }"
-c "PlenaryBustedDirectory $(TEST_DIR) { minimal_init = './test/minimal_init.vim', sequential = true }"

$(PLENARY_DIR):
git clone --depth=1 --no-single-branch $(PLENARY_URL) $(PLENARY_DIR)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ require('github-theme').setup({
darken = { -- Darken floating windows and sidebar-like windows
floats = true,
sidebars = {
enabled = true,
enable = true,
list = {}, -- Apply dark background to specific windows
},
},
Expand Down
6 changes: 3 additions & 3 deletions Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ Another setting is for sidebars, which is configured in the `sidebars` sub-table

#### options.darken.sidebars {table}

The `sidebars` sub table of `darken` contains settings for sidebar-like windows. It has two configurations: `enabled` is used to assign a darker background
to the listed windows, and `list` specifies the windows to be included in the list.
The `sidebars` sub table of `darken` contains settings for sidebar-like windows. It has two configurations: `enable` is used to assign a darker background
to the listed windows, and `list` specifies the windows to be darkened.

Example:

Expand All @@ -259,7 +259,7 @@ local options = {
darken = {
floats = false,
sidebars = {
enabled = true,
enable = true,
list = {'qf', 'netrw'} -- default is {}
}
}
Expand Down
6 changes: 3 additions & 3 deletions doc/github-nvim-theme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ sub-table.
options.darken.sidebars {table} *github-nvim-theme-options.darken.sidebars*

The `sidebars` sub table of `darken` contains settings for sidebar-like
windows. It has two configurations: `enabled` is used to assign a darker
windows. It has two configurations: `enable` is used to assign a darker
background to the listed windows, and `list` specifies the windows to be
included in the list.
darkened.

Example:

Expand All @@ -342,7 +342,7 @@ Example:
darken = {
floats = false,
sidebars = {
enabled = true,
enable = true,
list = {'qf', 'netrw'} -- default is {}
}
}
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 @@ -3,7 +3,7 @@ local C = require('github-theme.lib.color')
local M = {}

function M.get(spec, config)
local dark_sb = config.darken.sidebars.enabled
local dark_sb = config.darken.sidebars.enable
local hide_eof = config.hide_end_of_buffer
local inactive = config.dim_inactive
local inv = config.inverse
Expand Down
2 changes: 1 addition & 1 deletion lua/github-theme/group/modules/neotree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local M = {}

function M.get(spec, config, opts)
local hide_eof = config.hide_end_of_buffer
local dark_sb = config.darken.sidebars
local dark_sb = config.darken.sidebars.enable
local c = spec.palette

local function blend(color, a)
Expand Down
2 changes: 1 addition & 1 deletion lua/github-theme/group/modules/nvimtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local M = {}

function M.get(spec, config, opts)
local hide_eof = config.hide_end_of_buffer
local dark_sb = config.darken.sidebars
local dark_sb = config.darken.sidebars.enable
local c = spec.palette

-- stylua: ignore
Expand Down
10 changes: 10 additions & 0 deletions lua/github-theme/util/deprecation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ M.check_deprecation = function(opts)
' for more info.'
)
end

if (((opts.options or {}).darken or {}).sidebars or {}).enabled ~= nil then
dep.write(
' ',
{ 'options.darken.sidebars.enabled', 'WarningMsg' },
' has been renamed/reverted back to ',
{ 'options.darken.sidebars.enable', 'WarningMsg' }
)
end

M.checked_deprecation = true
end

Expand Down
86 changes: 79 additions & 7 deletions test/github-theme/config/darken_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,33 @@ local t_util = require('github-theme._test.util')
local C = require('github-theme.lib.color')
local api = vim.api

if not api.nvim_get_hl then
if
(vim.fn.has('nvim-0.10.0') == false or vim.fn.has('nvim-0.10.0') == 0)
and not api.nvim_get_hl
then
return
end

describe('config > options > darken', function()
before_each(function()
after_each(function()
-- Could reset more than just this, but this alone seems to work now that the
-- compiler is fixed.
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
local it_or_pending = variant:find('high[-_]*contrast') and pending or it

_it(('should be enabled by default (%s)'):format(variant), function()
it_or_pending(('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.are.not_equal(normal.bg, normal_float.bg)
assert(
C(('#%x'):format(normal_float.bg)):luminance()
< C(('#%x'):format(normal.bg)):luminance(),
Expand All @@ -40,10 +45,77 @@ describe('config > options > darken', function()
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)
assert.are.equal(normal.bg, normal_float.bg)
end)
end
end)

describe('> sidebars', function()
describe('> enable', function()
for _, variant in ipairs(require('github-theme.palette').themes) do
-- TODO: see #324
local it_or_pending = variant:find('high[-_]*contrast') and pending or it

it_or_pending(('should be enabled by default (%s)'):format(variant), function()
require('github-theme').setup()
vim.cmd.colorscheme({ args = { variant } })
local normal_sb = t_util.get_hl('NormalSB')
local normal = t_util.get_hl('Normal')

assert.is_true(require('github-theme.config').options.darken.sidebars.enable)
assert.are.not_equal(normal.bg, normal_sb.bg)
assert(
C(('#%x'):format(normal_sb.bg)):luminance()
< C(('#%x'):format(normal.bg)):luminance(),
('expected `bg` of `NormalFloat` (#%x) to be darker than `bg` of `Normal` (#%x)'):format(
normal_sb.bg,
normal.bg
)
)
end)

it(('should be disabled when set to `false` (%s)'):format(variant), function()
require('github-theme').setup({
options = { darken = { sidebars = { enable = false } } },
})

vim.cmd.colorscheme({ args = { variant } })
local normal_sb = t_util.get_hl('NormalSB')
local normal = t_util.get_hl('Normal')
assert.is_false(require('github-theme.config').options.darken.sidebars.enable)
assert.are.equal(normal.bg, normal_sb.bg)
end)

it(('should also accept `enabled` (%s)'):format(variant), function()
require('github-theme').setup({
options = { darken = { sidebars = { enabled = false } } },
})

vim.cmd.colorscheme({ args = { variant } })
local normal_sb = t_util.get_hl('NormalSB')
local normal = t_util.get_hl('Normal')
assert.is_false(require('github-theme.config').options.darken.sidebars.enable)
assert.are.equal(normal.bg, normal_sb.bg)
end)

it(
('should accept both `enable` and `enabled` but prefer `enable` (%s)'):format(
variant
),
function()
require('github-theme').setup({
options = { darken = { sidebars = { enable = false, enabled = true } } },
})

vim.cmd.colorscheme({ args = { variant } })
local normal_sb = t_util.get_hl('NormalSB')
local normal = t_util.get_hl('Normal')
assert.is_false(require('github-theme.config').options.darken.sidebars.enable)
assert.are.equal(normal.bg, normal_sb.bg)
end
)
end
end)
end)
end)

0 comments on commit 8541b58

Please sign in to comment.