Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add grapple window highlight groups #164

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,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