aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-11-06 22:20:34 +0100
committerGitHub <noreply@github.com>2022-11-06 22:20:34 +0100
commitf646ffb86122d11a0d640274ea5235c87c7c3fdb (patch)
tree3b29d931bb3695773fa2a2973c82400fec4a1ea0 /lua/mason-core
parentfix(gem): don't format executable (#634) (diff)
downloadmason-f646ffb86122d11a0d640274ea5235c87c7c3fdb.tar
mason-f646ffb86122d11a0d640274ea5235c87c7c3fdb.tar.gz
mason-f646ffb86122d11a0d640274ea5235c87c7c3fdb.tar.bz2
mason-f646ffb86122d11a0d640274ea5235c87c7c3fdb.tar.lz
mason-f646ffb86122d11a0d640274ea5235c87c7c3fdb.tar.xz
mason-f646ffb86122d11a0d640274ea5235c87c7c3fdb.tar.zst
mason-f646ffb86122d11a0d640274ea5235c87c7c3fdb.zip
feat(ui): add MasonNormal highlight (#636)
Diffstat (limited to 'lua/mason-core')
-rw-r--r--lua/mason-core/ui/display.lua24
1 files changed, 10 insertions, 14 deletions
diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua
index 93bdf96f..f59d0952 100644
--- a/lua/mason-core/ui/display.lua
+++ b/lua/mason-core/ui/display.lua
@@ -165,9 +165,9 @@ end
-- exported for tests
M._render_node = render_node
----@alias WindowOpts {effects: table<string, fun()>, highlight_groups: table<string, table>, border: string|table}
+---@alias WindowOpts { effects?: table<string, fun()>, winhighlight?: string[], border?: string|table }
----@param opts WindowOpenOpts
+---@param opts WindowOpts
---@param sizes_only boolean Whether to only return properties that control the window size.
local function create_popup_window_opts(opts, sizes_only)
local win_height = vim.o.lines - vim.o.cmdheight - 2 -- Add margin for status and buffer line
@@ -348,10 +348,9 @@ function M.new_view_only_win(name, filetype)
end
end
- ---@param opts WindowOpenOpts
- local function open(opts)
+ local function open()
bufnr = vim.api.nvim_create_buf(false, true)
- win_id = vim.api.nvim_open_win(bufnr, true, create_popup_window_opts(opts, false))
+ win_id = vim.api.nvim_open_win(bufnr, true, create_popup_window_opts(window_opts, false))
registered_effect_handlers = window_opts.effects
registered_keybinds = {}
@@ -384,6 +383,10 @@ function M.new_view_only_win(name, filetype)
vim.api.nvim_win_set_option(win_id, key, value)
end
+ if window_opts.winhighlight then
+ vim.api.nvim_win_set_option(win_id, "winhighlight", table.concat(window_opts.winhighlight, ","))
+ end
+
-- buffer options
for key, value in pairs(buf_opts) do
vim.api.nvim_buf_set_option(bufnr, key, value)
@@ -466,16 +469,9 @@ function M.new_view_only_win(name, filetype)
assert(renderer ~= nil, "No view function has been registered. Call .view() before .init().")
assert(unsubscribe ~= nil, "No state has been registered. Call .state() before .init().")
window_opts = opts
- if opts.highlight_groups then
- for hl_name, args in pairs(opts.highlight_groups) do
- vim.api.nvim_set_hl(0, hl_name, args)
- end
- end
has_initiated = true
end,
- ---@alias WindowOpenOpts { border: string | table }
- ---@type fun(opts: WindowOpenOpts)
- open = vim.schedule_wrap(function(opts)
+ open = vim.schedule_wrap(function()
log.trace "Opening window"
assert(has_initiated, "Display has not been initiated, cannot open.")
if win_id and vim.api.nvim_win_is_valid(win_id) then
@@ -483,7 +479,7 @@ function M.new_view_only_win(name, filetype)
return
end
unsubscribe(false)
- open(opts)
+ open()
draw(renderer(get_state()))
end),
---@type fun()