Merge pull request #94 from barrettruth/feat/highlight-config-overrides
Highlight config overrides, default flag, blend alpha
This commit is contained in:
commit
52013d007d
3 changed files with 60 additions and 11 deletions
|
|
@ -18,7 +18,8 @@ syntax highlighting.
|
||||||
- Vim syntax fallback for languages without a treesitter parser
|
- Vim syntax fallback for languages without a treesitter parser
|
||||||
- Hunk header context highlighting (`@@ ... @@ function foo()`)
|
- Hunk header context highlighting (`@@ ... @@ function foo()`)
|
||||||
- Character-level (intra-line) diff highlighting for changed characters
|
- Character-level (intra-line) diff highlighting for changed characters
|
||||||
- Configurable debouncing, max lines, and diff prefix concealment
|
- Configurable debouncing, max lines, diff prefix concealment, blend alpha, and
|
||||||
|
highlight overrides
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
||||||
highlights = {
|
highlights = {
|
||||||
background = true,
|
background = true,
|
||||||
gutter = true,
|
gutter = true,
|
||||||
|
blend_alpha = 0.6,
|
||||||
context = {
|
context = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
lines = 25,
|
lines = 25,
|
||||||
|
|
@ -66,13 +67,14 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
||||||
},
|
},
|
||||||
vim = {
|
vim = {
|
||||||
enabled = false,
|
enabled = false,
|
||||||
max_lines = 500,
|
max_lines = 200,
|
||||||
},
|
},
|
||||||
intra = {
|
intra = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
algorithm = 'default',
|
algorithm = 'default',
|
||||||
max_lines = 500,
|
max_lines = 500,
|
||||||
},
|
},
|
||||||
|
overrides = {},
|
||||||
},
|
},
|
||||||
fugitive = {
|
fugitive = {
|
||||||
horizontal = 'du',
|
horizontal = 'du',
|
||||||
|
|
@ -117,6 +119,13 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
||||||
Highlight line numbers with matching colors.
|
Highlight line numbers with matching colors.
|
||||||
Only visible if line numbers are enabled.
|
Only visible if line numbers are enabled.
|
||||||
|
|
||||||
|
{blend_alpha} (number, default: 0.6)
|
||||||
|
Alpha value for character-level blend intensity.
|
||||||
|
Controls how strongly changed characters stand
|
||||||
|
out from the line-level background. Must be
|
||||||
|
between 0 and 1 (inclusive). Higher values
|
||||||
|
produce more vivid character-level highlights.
|
||||||
|
|
||||||
{context} (table, default: see below)
|
{context} (table, default: see below)
|
||||||
Syntax parsing context options.
|
Syntax parsing context options.
|
||||||
See |diffs.ContextConfig| for fields.
|
See |diffs.ContextConfig| for fields.
|
||||||
|
|
@ -133,6 +142,13 @@ Configuration is done via `vim.g.diffs`. Set this before the plugin loads:
|
||||||
Character-level (intra-line) diff highlighting.
|
Character-level (intra-line) diff highlighting.
|
||||||
See |diffs.IntraConfig| for fields.
|
See |diffs.IntraConfig| for fields.
|
||||||
|
|
||||||
|
{overrides} (table, default: {})
|
||||||
|
Map of highlight group names to highlight
|
||||||
|
definitions (see |nvim_set_hl()|). Applied
|
||||||
|
after all computed groups without `default`,
|
||||||
|
so overrides always win over both computed
|
||||||
|
defaults and colorscheme definitions.
|
||||||
|
|
||||||
*diffs.ContextConfig*
|
*diffs.ContextConfig*
|
||||||
Context config fields: ~
|
Context config fields: ~
|
||||||
{enabled} (boolean, default: true)
|
{enabled} (boolean, default: true)
|
||||||
|
|
@ -398,9 +414,9 @@ diff-related features.
|
||||||
==============================================================================
|
==============================================================================
|
||||||
HIGHLIGHT GROUPS *diffs-highlights*
|
HIGHLIGHT GROUPS *diffs-highlights*
|
||||||
|
|
||||||
diffs.nvim defines custom highlight groups. Fugitive unified diff groups use
|
diffs.nvim defines custom highlight groups. All groups use `default = true`,
|
||||||
`default = true`, so colorschemes can override them. Diff mode groups are
|
so colorschemes can override them by defining the group before the plugin
|
||||||
always derived from the corresponding `Diff*` groups.
|
loads.
|
||||||
|
|
||||||
All derived groups are computed by alpha-blending a source color into the
|
All derived groups are computed by alpha-blending a source color into the
|
||||||
`Normal` background. Line-level groups blend at 40% alpha for a subtle tint;
|
`Normal` background. Line-level groups blend at 40% alpha for a subtle tint;
|
||||||
|
|
@ -461,6 +477,16 @@ To customize these in your colorscheme: >lua
|
||||||
vim.api.nvim_set_hl(0, 'DiffsAdd', { bg = '#2e4a3a' })
|
vim.api.nvim_set_hl(0, 'DiffsAdd', { bg = '#2e4a3a' })
|
||||||
vim.api.nvim_set_hl(0, 'DiffsDiffDelete', { link = 'DiffDelete' })
|
vim.api.nvim_set_hl(0, 'DiffsDiffDelete', { link = 'DiffDelete' })
|
||||||
<
|
<
|
||||||
|
Or via `highlights.overrides` in config: >lua
|
||||||
|
vim.g.diffs = {
|
||||||
|
highlights = {
|
||||||
|
overrides = {
|
||||||
|
DiffsAdd = { bg = '#2e4a3a' },
|
||||||
|
DiffsDiffDelete = { link = 'DiffDelete' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
HEALTH CHECK *diffs-health*
|
HEALTH CHECK *diffs-health*
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
---@class diffs.Highlights
|
---@class diffs.Highlights
|
||||||
---@field background boolean
|
---@field background boolean
|
||||||
---@field gutter boolean
|
---@field gutter boolean
|
||||||
|
---@field blend_alpha? number
|
||||||
|
---@field overrides? table<string, table>
|
||||||
---@field context diffs.ContextConfig
|
---@field context diffs.ContextConfig
|
||||||
---@field treesitter diffs.TreesitterConfig
|
---@field treesitter diffs.TreesitterConfig
|
||||||
---@field vim diffs.VimConfig
|
---@field vim diffs.VimConfig
|
||||||
|
|
@ -192,8 +194,9 @@ local function compute_highlight_groups()
|
||||||
local blended_add = blend_color(add_bg, bg, 0.4)
|
local blended_add = blend_color(add_bg, bg, 0.4)
|
||||||
local blended_del = blend_color(del_bg, bg, 0.4)
|
local blended_del = blend_color(del_bg, bg, 0.4)
|
||||||
|
|
||||||
local blended_add_text = blend_color(add_fg, bg, 0.6)
|
local alpha = config.highlights.blend_alpha or 0.6
|
||||||
local blended_del_text = blend_color(del_fg, bg, 0.6)
|
local blended_add_text = blend_color(add_fg, bg, alpha)
|
||||||
|
local blended_del_text = blend_color(del_fg, bg, alpha)
|
||||||
|
|
||||||
vim.api.nvim_set_hl(0, 'DiffsClear', { default = true, fg = normal.fg or 0xc0c0c0 })
|
vim.api.nvim_set_hl(0, 'DiffsClear', { default = true, fg = normal.fg or 0xc0c0c0 })
|
||||||
vim.api.nvim_set_hl(0, 'DiffsAdd', { default = true, bg = blended_add })
|
vim.api.nvim_set_hl(0, 'DiffsAdd', { default = true, bg = blended_add })
|
||||||
|
|
@ -219,10 +222,20 @@ local function compute_highlight_groups()
|
||||||
local diff_change = resolve_hl('DiffChange')
|
local diff_change = resolve_hl('DiffChange')
|
||||||
local diff_text = resolve_hl('DiffText')
|
local diff_text = resolve_hl('DiffText')
|
||||||
|
|
||||||
vim.api.nvim_set_hl(0, 'DiffsDiffAdd', { bg = diff_add.bg })
|
vim.api.nvim_set_hl(0, 'DiffsDiffAdd', { default = true, bg = diff_add.bg })
|
||||||
vim.api.nvim_set_hl(0, 'DiffsDiffDelete', { fg = diff_delete.fg, bg = diff_delete.bg })
|
vim.api.nvim_set_hl(
|
||||||
vim.api.nvim_set_hl(0, 'DiffsDiffChange', { bg = diff_change.bg })
|
0,
|
||||||
vim.api.nvim_set_hl(0, 'DiffsDiffText', { bg = diff_text.bg })
|
'DiffsDiffDelete',
|
||||||
|
{ default = true, fg = diff_delete.fg, bg = diff_delete.bg }
|
||||||
|
)
|
||||||
|
vim.api.nvim_set_hl(0, 'DiffsDiffChange', { default = true, bg = diff_change.bg })
|
||||||
|
vim.api.nvim_set_hl(0, 'DiffsDiffText', { default = true, bg = diff_text.bg })
|
||||||
|
|
||||||
|
if config.highlights.overrides then
|
||||||
|
for group, hl in pairs(config.highlights.overrides) do
|
||||||
|
vim.api.nvim_set_hl(0, group, hl)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function init()
|
local function init()
|
||||||
|
|
@ -244,6 +257,8 @@ local function init()
|
||||||
vim.validate({
|
vim.validate({
|
||||||
['highlights.background'] = { opts.highlights.background, 'boolean', true },
|
['highlights.background'] = { opts.highlights.background, 'boolean', true },
|
||||||
['highlights.gutter'] = { opts.highlights.gutter, 'boolean', true },
|
['highlights.gutter'] = { opts.highlights.gutter, 'boolean', true },
|
||||||
|
['highlights.blend_alpha'] = { opts.highlights.blend_alpha, 'number', true },
|
||||||
|
['highlights.overrides'] = { opts.highlights.overrides, 'table', true },
|
||||||
['highlights.context'] = { opts.highlights.context, 'table', true },
|
['highlights.context'] = { opts.highlights.context, 'table', true },
|
||||||
['highlights.treesitter'] = { opts.highlights.treesitter, 'table', true },
|
['highlights.treesitter'] = { opts.highlights.treesitter, 'table', true },
|
||||||
['highlights.vim'] = { opts.highlights.vim, 'table', true },
|
['highlights.vim'] = { opts.highlights.vim, 'table', true },
|
||||||
|
|
@ -344,6 +359,13 @@ local function init()
|
||||||
then
|
then
|
||||||
error('diffs: highlights.intra.max_lines must be >= 1')
|
error('diffs: highlights.intra.max_lines must be >= 1')
|
||||||
end
|
end
|
||||||
|
if
|
||||||
|
opts.highlights
|
||||||
|
and opts.highlights.blend_alpha
|
||||||
|
and (opts.highlights.blend_alpha < 0 or opts.highlights.blend_alpha > 1)
|
||||||
|
then
|
||||||
|
error('diffs: highlights.blend_alpha must be >= 0 and <= 1')
|
||||||
|
end
|
||||||
|
|
||||||
config = vim.tbl_deep_extend('force', default_config, opts)
|
config = vim.tbl_deep_extend('force', default_config, opts)
|
||||||
log.set_enabled(config.debug)
|
log.set_enabled(config.debug)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue