diff --git a/README.md b/README.md index 2413725..fbec4f9 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,7 @@ require('github-theme').setup({ transparent = false, -- Disable setting bg (make neovim's background transparent) terminal_colors = true, -- Set terminal colors (vim.g.terminal_color_*) used in `:terminal` dim_inactive = false, -- Non focused panes set to alternative background + cursor = false, -- Set guicursor to use the theme's Cursor highlight groups module_default = true, -- Default enable value for modules styles = { -- Style to be applied to different syntax groups comments = 'NONE', -- Value is any valid attr-list value `:help attr-list` diff --git a/Usage.md b/Usage.md index ca12073..49cf920 100644 --- a/Usage.md +++ b/Usage.md @@ -203,6 +203,13 @@ If set to `true`, it defines the terminal colors for the built-in `terminal` (vi If set to `true`, it sets the background of non-current windows to be darker. Refer to `:h hl-NormalNC` for more information. +#### options.cursor {bool} + +If set to `true`, it sets `guicursor` so that the cursor uses the colors of the theme's `Cursor`/`lCursor` highlight groups. +By default, Neovim renders the cursor with the host-terminal default colors and ignores the `Cursor` highlight group, which can +make the cursor hard to see on light themes. With this option enabled, e.g. on `github_light` the cursor becomes the theme's +foreground color (`#1F2328`) with a light glyph. The default value is `false`. + #### options.module_default {bool} Specifies the default value of a module that has not been overridden in the modules table. diff --git a/doc/github-nvim-theme.txt b/doc/github-nvim-theme.txt index 4c0394b..8e8cb7c 100644 --- a/doc/github-nvim-theme.txt +++ b/doc/github-nvim-theme.txt @@ -274,6 +274,16 @@ If set to `true`, it sets the background of non-current windows to be darker. Refer to `:h hl-NormalNC` for more information. +options.cursor {bool} *github-nvim-theme-options.cursor* + +If set to `true`, it sets `guicursor` so that the cursor uses the colors of the +theme's `Cursor`/`lCursor` highlight groups. By default, Neovim renders the +cursor with the host-terminal default colors and ignores the `Cursor` highlight +group, which can make the cursor hard to see on light themes. With this option +enabled, e.g. on `github_light` the cursor becomes the theme's foreground color +(`#1F2328`) with a light glyph. The default value is `false`. + + options.module_default {bool} *github-nvim-theme-options.module_default* Specifies the default value of a module that has not been overridden in the diff --git a/lua/github-theme/config.lua b/lua/github-theme/config.lua index a48bebb..961ea68 100644 --- a/lua/github-theme/config.lua +++ b/lua/github-theme/config.lua @@ -22,6 +22,7 @@ local M = { theme = 'github_dark', has_options = false } ---@field transparent? boolean ---@field terminal_colors? boolean ---@field dim_inactive? boolean +---@field cursor? boolean ---@field module_default? boolean ---@field styles? GhTheme.Config.Options.Styles ---@field inverse? GhTheme.Config.Options.Inverse @@ -37,6 +38,12 @@ local defaults = { dim_inactive = false, module_default = true, + ---If set to `true`, `guicursor` is set so that the cursor uses the colors of + ---the theme's `Cursor`/`lCursor` highlight groups, instead of the + ---host-terminal default cursor colors. + ---@field cursor? boolean + cursor = false, + ---A table of syntax items/groups and their corresponding styles. ---@class (exact) GhTheme.Config.Options.Styles ---@field comments? GhTheme.HighlightGroup.Style diff --git a/lua/github-theme/init.lua b/lua/github-theme/init.lua index 59cd4d0..963cf99 100644 --- a/lua/github-theme/init.lua +++ b/lua/github-theme/init.lua @@ -94,6 +94,12 @@ function M.load(opts) ---@diagnostic disable-next-line: need-check-nil compiled_theme() + + if config.options.cursor then + vim.opt.guicursor = + 'n-v-c-sm:block-Cursor/lCursor,i-ci-ve:ver25-Cursor,r-cr-o:hor20-Cursor,t:block-blinkon500-blinkoff500-TermCursor' + end + require('github-theme.autocmds').set_autocmds() end diff --git a/test/github-theme/config/cursor_spec.lua b/test/github-theme/config/cursor_spec.lua new file mode 100644 index 0000000..f1ab888 --- /dev/null +++ b/test/github-theme/config/cursor_spec.lua @@ -0,0 +1,24 @@ +if vim.fn.has('nvim-0.9.0') == 0 or vim.fn.has('nvim-0.9.0') == false then + return +end + +describe('config > options > cursor', function() + before_each(function() + require('github-theme.util.reload')(true) + end) + + it('should not set `guicursor` when disabled', function() + require('github-theme').setup() + vim.cmd.colorscheme({ args = { 'github_light' } }) + assert.is_false(require('github-theme.config').options.cursor) + assert.is_not.match('%-Cursor', vim.o.guicursor) + end) + + it('should reference the `Cursor` highlight groups when enabled', function() + require('github-theme').setup({ options = { cursor = true } }) + vim.cmd.colorscheme({ args = { 'github_light' } }) + assert.is_true(require('github-theme.config').options.cursor) + assert.is.match('block%-Cursor/lCursor', vim.o.guicursor) + assert.is.match('ver25%-Cursor', vim.o.guicursor) + end) +end) \ No newline at end of file