diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-16 14:03:55 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-16 14:13:49 +0100 |
| commit | c8a5c2dfd256b780a30f37d69cfe9c407db4bf5e (patch) | |
| tree | 75f0006d5d87473b4d10fd325e66be006c97632a /lua | |
| parent | chore: merge dev (diff) | |
feat(popup): popup options / hopefully fix black square
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets.lua | 24 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 18 | ||||
| -rw-r--r-- | lua/pets/utils.lua | 9 |
3 files changed, 34 insertions, 17 deletions
diff --git a/lua/pets.lua b/lua/pets.lua index 10bccbc..30f3ef7 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -9,6 +9,7 @@ M.options = { default_style = "brown", random = true, death_animation = true, + popup = { width = "30%", winblend = 100, hl = { Normal = "Normal" }, avoid_statusline = false }, } M.pets = {} @@ -17,6 +18,29 @@ function M.setup(options) options = options or {} M.options = vim.tbl_deep_extend("force", M.options, options) + -- popup opts + local popup_opts = { + position = { + row = "100%", + col = "100%", + }, + size = { + width = M.options.popup.width, + height = 10, + }, + focusable = false, + enter = false, + win_options = { + winblend = M.options.popup.winblend, + }, + } + if M.options.popup.avoid_statusline then + local hl = utils.parse_popup_hl(M.options.popup.hl) + popup_opts.position.row = "99%" + popup_opts.win_options = { winhighlight = hl } + end + M.options.popup = popup_opts + -- init hologram local ok = pcall(require, "hologram") if ok then diff --git a/lua/pets/pet.lua b/lua/pets/pet.lua index 0cdd77b..5f5dbc4 100644 --- a/lua/pets/pet.lua +++ b/lua/pets/pet.lua @@ -3,22 +3,6 @@ local M = {} M.Pet = {} M.Pet.__index = M.Pet -local popup_opts = { - position = { - row = "100%", - col = "100%", - }, - size = { - width = "30%", - height = 10, - }, - focusable = false, - enter = false, - win_options = { - winblend = 100, - }, -} - -- @param name the actual name for the pet -- @param type the species of the pet e.g. cat -- @param style the color/style of the pet e.g. brown @@ -34,7 +18,7 @@ function M.Pet.new(name, type, style, user_opts) local wd = debug.getinfo(1).source:sub(2):match("(.*nvim/)") .. "media/" instance.sourcedir = wd .. type .. "/" .. style .. "/" - instance.popup = require("nui.popup")(popup_opts) + instance.popup = require("nui.popup")(user_opts.popup) instance.animation = require("pets.animations").Animation.new(instance.sourcedir, type, style, instance.popup, user_opts) return instance diff --git a/lua/pets/utils.lua b/lua/pets/utils.lua index 90f933d..dbf1191 100644 --- a/lua/pets/utils.lua +++ b/lua/pets/utils.lua @@ -79,4 +79,13 @@ function M.warning(msg) vim.notify(msg, vim.log.levels.WARN) end +function M.parse_popup_hl(highlight) + return table.concat( + vim.tbl_map(function(key) + return key .. ":" .. highlight[key] + end, vim.tbl_keys(highlight)), + "," + ) +end + return M |