Skip to content

Commit dd7fd96

Browse files
feat: add grapple window highlight groups (#164)
* feat: add grapple window highlight groups * docs: update grapple highlights table
1 parent 4b54261 commit dd7fd96

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,10 @@ require("grapple").open_loaded({ all = true })
936936
| `GrappleName` | `DiagnosticHint` | N/A | Tags window for tag name |
937937
| `GrappleNoExist` | `DiagnosticError` | N/A | Tags window for tag status |
938938
| `GrappleCurrent` | `SpecialChar` | `gui=bold` | All windows for current status |
939+
| `GrappleFloat` | `NormalFloat` | N/A | All windows for background |
940+
| `GrappleBorder` | `FloatBorder` | N/A | All windows for border |
941+
| `GrappleTitle` | `FloatTitle` | N/A | All windows for title |
942+
| `GrappleFooter` | `FloatFooter` | N/A | All windows for footer |
939943

940944
## Persistent State
941945

lua/grapple/window.lua

+22
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ function Window:open()
128128
local win_opts = self:window_options()
129129
self.win_id = vim.api.nvim_open_win(self.buf_id, true, win_opts)
130130

131+
-- Set window highlights
132+
self:set_highlight("NormalFloat", "GrappleNormal")
133+
self:set_highlight("FloatBorder", "GrappleBorder")
134+
self:set_highlight("FloatTitle", "GrappleTitle")
135+
self:set_highlight("FloatFooter", "GrappleFooter")
136+
131137
-- Setup window to conceal line IDs
132138
vim.api.nvim_set_option_value("concealcursor", "nvic", { win = self.win_id })
133139
vim.api.nvim_set_option_value("conceallevel", 3, { win = self.win_id })
@@ -607,4 +613,20 @@ function Window:alternate_path()
607613
return Path.fs_absolute(alt_name)
608614
end
609615

616+
--- Replaces a highlight group in the window
617+
--- @param new_from string
618+
--- @param new_to string
619+
function Window:set_highlight(new_from, new_to)
620+
local new_entry = new_from .. ":" .. new_to
621+
local replace_pattern = string.format("(%s:[^,]*)", vim.pesc(new_from))
622+
local new_winhighlight, n_replace = vim.wo[self.win_id].winhighlight:gsub(replace_pattern, new_entry)
623+
if n_replace == 0 then
624+
new_winhighlight = new_winhighlight .. "," .. new_entry
625+
end
626+
627+
pcall(function()
628+
vim.wo[self.win_id].winhighlight = new_winhighlight
629+
end)
630+
end
631+
610632
return Window

plugin/grapple.lua

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ vim.cmd("highlight default GrappleBold gui=bold cterm=bold")
66
vim.cmd("highlight default link GrappleHint Comment")
77
vim.cmd("highlight default link GrappleName DiagnosticHint")
88
vim.cmd("highlight default link GrappleNoExist DiagnosticError")
9+
vim.cmd("highlight default link GrappleNormal NormalFloat")
10+
vim.cmd("highlight default link GrappleBorder FloatBorder")
11+
vim.cmd("highlight default link GrappleTitle FloatTitle")
12+
vim.cmd("highlight default link GrappleFooter FloatFooter")
913

1014
vim.cmd("highlight default GrappleCurrent gui=bold cterm=bold")
1115
vim.cmd("highlight! link GrappleCurrent SpecialChar")

0 commit comments

Comments
 (0)