Skip to content

Commit

Permalink
feat: add grapple window highlight groups (#164)
Browse files Browse the repository at this point in the history
* feat: add grapple window highlight groups

* docs: update grapple highlights table
  • Loading branch information
scottmckendry authored May 18, 2024
1 parent 4b54261 commit dd7fd96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,10 @@ require("grapple").open_loaded({ all = true })
| `GrappleName` | `DiagnosticHint` | N/A | Tags window for tag name |
| `GrappleNoExist` | `DiagnosticError` | N/A | Tags window for tag status |
| `GrappleCurrent` | `SpecialChar` | `gui=bold` | All windows for current status |
| `GrappleFloat` | `NormalFloat` | N/A | All windows for background |
| `GrappleBorder` | `FloatBorder` | N/A | All windows for border |
| `GrappleTitle` | `FloatTitle` | N/A | All windows for title |
| `GrappleFooter` | `FloatFooter` | N/A | All windows for footer |

## Persistent State

Expand Down
22 changes: 22 additions & 0 deletions lua/grapple/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ function Window:open()
local win_opts = self:window_options()
self.win_id = vim.api.nvim_open_win(self.buf_id, true, win_opts)

-- Set window highlights
self:set_highlight("NormalFloat", "GrappleNormal")
self:set_highlight("FloatBorder", "GrappleBorder")
self:set_highlight("FloatTitle", "GrappleTitle")
self:set_highlight("FloatFooter", "GrappleFooter")

-- Setup window to conceal line IDs
vim.api.nvim_set_option_value("concealcursor", "nvic", { win = self.win_id })
vim.api.nvim_set_option_value("conceallevel", 3, { win = self.win_id })
Expand Down Expand Up @@ -607,4 +613,20 @@ function Window:alternate_path()
return Path.fs_absolute(alt_name)
end

--- Replaces a highlight group in the window
--- @param new_from string
--- @param new_to string
function Window:set_highlight(new_from, new_to)
local new_entry = new_from .. ":" .. new_to
local replace_pattern = string.format("(%s:[^,]*)", vim.pesc(new_from))
local new_winhighlight, n_replace = vim.wo[self.win_id].winhighlight:gsub(replace_pattern, new_entry)
if n_replace == 0 then
new_winhighlight = new_winhighlight .. "," .. new_entry
end

pcall(function()
vim.wo[self.win_id].winhighlight = new_winhighlight
end)
end

return Window
4 changes: 4 additions & 0 deletions plugin/grapple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ vim.cmd("highlight default GrappleBold gui=bold cterm=bold")
vim.cmd("highlight default link GrappleHint Comment")
vim.cmd("highlight default link GrappleName DiagnosticHint")
vim.cmd("highlight default link GrappleNoExist DiagnosticError")
vim.cmd("highlight default link GrappleNormal NormalFloat")
vim.cmd("highlight default link GrappleBorder FloatBorder")
vim.cmd("highlight default link GrappleTitle FloatTitle")
vim.cmd("highlight default link GrappleFooter FloatFooter")

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

0 comments on commit dd7fd96

Please sign in to comment.