From e00c67b0cc5428f08bd4ac5bdc9a500d654059f0 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Wed, 20 Sep 2023 19:15:07 -0700 Subject: [PATCH 1/2] fix(palette): get `canvas` from primitives This should also correct any issues with the `Normal` bg being off or incorrect, as this color (i.e. the `Normal` bg, the global bg) ultimately derives from `canvas.default` (found in the palette). Fixes #298 --- lua/github-theme/palette/github_dark.lua | 9 ++------- lua/github-theme/palette/github_dark_colorblind.lua | 9 ++------- lua/github-theme/palette/github_dark_dimmed.lua | 9 ++------- lua/github-theme/palette/github_dark_high_contrast.lua | 9 ++------- lua/github-theme/palette/github_dark_tritanopia.lua | 9 ++------- lua/github-theme/palette/github_light.lua | 9 ++------- lua/github-theme/palette/github_light_colorblind.lua | 9 ++------- lua/github-theme/palette/github_light_high_contrast.lua | 9 ++------- lua/github-theme/palette/github_light_tritanopia.lua | 9 ++------- 9 files changed, 18 insertions(+), 63 deletions(-) diff --git a/lua/github-theme/palette/github_dark.lua b/lua/github-theme/palette/github_dark.lua index 7bf31b76..477cffe6 100755 --- a/lua/github-theme/palette/github_dark.lua +++ b/lua/github-theme/palette/github_dark.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.gray[7]) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -42,12 +42,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.gray[7], - overlay = scale.gray[9], - inset = scale.gray[8], - subtle = scale.gray[9], - }, + canvas = primitives.canvas, border = { default = scale.gray[9], diff --git a/lua/github-theme/palette/github_dark_colorblind.lua b/lua/github-theme/palette/github_dark_colorblind.lua index cc78cfea..28a11cd8 100644 --- a/lua/github-theme/palette/github_dark_colorblind.lua +++ b/lua/github-theme/palette/github_dark_colorblind.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.gray[10]) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -42,12 +42,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.gray[10], - overlay = scale.gray[9], - inset = scale.black, - subtle = scale.gray[9], - }, + canvas = primitives.canvas, border = { default = scale.gray[7], diff --git a/lua/github-theme/palette/github_dark_dimmed.lua b/lua/github-theme/palette/github_dark_dimmed.lua index 69ecdcb1..ccb9e34b 100644 --- a/lua/github-theme/palette/github_dark_dimmed.lua +++ b/lua/github-theme/palette/github_dark_dimmed.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.gray[10]) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -42,12 +42,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.gray[10], - overlay = scale.gray[9], - inset = scale.black, - subtle = scale.gray[9], - }, + canvas = primitives.canvas, border = { default = scale.gray[7], diff --git a/lua/github-theme/palette/github_dark_high_contrast.lua b/lua/github-theme/palette/github_dark_high_contrast.lua index 66c037c9..b52ea4fe 100644 --- a/lua/github-theme/palette/github_dark_high_contrast.lua +++ b/lua/github-theme/palette/github_dark_high_contrast.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.gray[10]) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -42,12 +42,7 @@ local palette = { on_emphasis = scale.gray[10], }, - canvas = { - default = scale.gray[10], - overlay = scale.gray[9], - inset = scale.black, - subtle = scale.gray[9], - }, + canvas = primitives.canvas, border = { default = scale.gray[4], diff --git a/lua/github-theme/palette/github_dark_tritanopia.lua b/lua/github-theme/palette/github_dark_tritanopia.lua index 0b9e4966..a60c0103 100644 --- a/lua/github-theme/palette/github_dark_tritanopia.lua +++ b/lua/github-theme/palette/github_dark_tritanopia.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.gray[10]) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -42,12 +42,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.gray[10], - overlay = scale.gray[9], - inset = scale.black, - subtle = scale.gray[9], - }, + canvas = primitives.canvas, border = { default = scale.gray[7], diff --git a/lua/github-theme/palette/github_light.lua b/lua/github-theme/palette/github_light.lua index 4de3f80c..af9645a5 100644 --- a/lua/github-theme/palette/github_light.lua +++ b/lua/github-theme/palette/github_light.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.white) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -43,12 +43,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.white, - overlay = scale.white, - inset = scale.gray[1], - subtle = scale.gray[1], - }, + canvas = primitives.canvas, border = { default = scale.gray[3], diff --git a/lua/github-theme/palette/github_light_colorblind.lua b/lua/github-theme/palette/github_light_colorblind.lua index f88e7d0e..8bd64d87 100644 --- a/lua/github-theme/palette/github_light_colorblind.lua +++ b/lua/github-theme/palette/github_light_colorblind.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.white) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -43,12 +43,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.white, - overlay = scale.white, - inset = scale.gray[1], - subtle = scale.gray[1], - }, + canvas = primitives.canvas, border = { default = scale.gray[3], diff --git a/lua/github-theme/palette/github_light_high_contrast.lua b/lua/github-theme/palette/github_light_high_contrast.lua index 04769424..62123174 100644 --- a/lua/github-theme/palette/github_light_high_contrast.lua +++ b/lua/github-theme/palette/github_light_high_contrast.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.white) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -43,12 +43,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.white, - overlay = scale.white, - inset = scale.white, - subtle = scale.gray[2], - }, + canvas = primitives.canvas, border = { default = scale.gray[9], diff --git a/lua/github-theme/palette/github_light_tritanopia.lua b/lua/github-theme/palette/github_light_tritanopia.lua index 7a174dc3..730d678c 100644 --- a/lua/github-theme/palette/github_light_tritanopia.lua +++ b/lua/github-theme/palette/github_light_tritanopia.lua @@ -13,7 +13,7 @@ local scale = primitives.scale C.WHITE = C(scale.white) C.BLACK = C(scale.black) -C.BG = C(scale.white) +C.BG = C(assert(primitives.canvas.default)) local function alpha(color, a) return color:alpha_blend(a):to_css() @@ -43,12 +43,7 @@ local palette = { on_emphasis = scale.white, }, - canvas = { - default = scale.white, - overlay = scale.white, - inset = scale.gray[1], - subtle = scale.gray[1], - }, + canvas = primitives.canvas, border = { default = scale.gray[3], From da1edb862467ef88e6fd209c3bfbda791f23d702 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Wed, 20 Sep 2023 22:34:56 -0700 Subject: [PATCH 2/2] test: add rudimentary smoke tests to check for errors --- lua/github-theme/_test/util.lua | 21 +++++++++++++ test/github-theme/smoketest/startup_spec.lua | 33 ++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 lua/github-theme/_test/util.lua create mode 100644 test/github-theme/smoketest/startup_spec.lua diff --git a/lua/github-theme/_test/util.lua b/lua/github-theme/_test/util.lua new file mode 100644 index 00000000..8bc18690 --- /dev/null +++ b/lua/github-theme/_test/util.lua @@ -0,0 +1,21 @@ +local M = {} +local api = vim.api + +function M.await_VimEnter() + if vim.v.vim_did_enter == 0 then + local co = assert(coroutine.running(), 'test is not running in coroutine') + + api.nvim_create_autocmd('VimEnter', { + pattern = '*', + once = true, + nested = true, + callback = vim.schedule_wrap(function() + coroutine.resume(co) + end), + }) + + coroutine.yield() + end +end + +return M diff --git a/test/github-theme/smoketest/startup_spec.lua b/test/github-theme/smoketest/startup_spec.lua new file mode 100644 index 00000000..601d30d5 --- /dev/null +++ b/test/github-theme/smoketest/startup_spec.lua @@ -0,0 +1,33 @@ +local assert = require('luassert') +local t_util = require('github-theme._test.util') + +describe('(smoke test)', function() + describe('setting colorscheme during startup', function() + it('should not error', function() + assert.does_not_error(function() + vim.cmd('colorscheme github_dark_dimmed') + end) + + assert.is.equal('', vim.v.errmsg or '') + end) + end) + + describe('setting/switching colorscheme post-startup', function() + it('should not error', function() + t_util.await_VimEnter() + + for _, cs in ipairs({ + 'default', + 'github_dark_dimmed', + 'github_dark_dimmed', + 'github_light', + }) do + assert.does_not_error(function() + vim.cmd('colorscheme ' .. cs) + end) + + assert.is.equal('', vim.v.errmsg or '') + end + end) + end) +end)