diff options
| -rw-r--r-- | README.md | 12 | ||||
| -rw-r--r-- | lua/pets.lua | 24 | ||||
| -rw-r--r-- | lua/pets/pet.lua | 18 | ||||
| -rw-r--r-- | lua/pets/utils.lua | 9 |
4 files changed, 46 insertions, 17 deletions
@@ -2,6 +2,7 @@ Pets.nvim is a plugin that provides the missing core functionality of showing little animal friends inside your editor. It relies on the [kitty graphics protocol](https://sw.kovidgoyal.net/kitty/graphics-protocol/) and [hologram.nvim](https://github.com/edluffy/hologram.nvim) to be able to display images in a terminal window. As you might know the plugin is heavily inspired by [vscode-pets](https://github.com/tonybaloney/vscode-pets/tree/master/media). +If you like the art for the pets, check out the [Credits](#-Credits) section.  @@ -47,8 +48,19 @@ This is the default configuration: default_style = "brown", -- the style of the pet to use for the PetNew command random = false, -- wether to use a random pet for the PetNew command, ovverides default_pet and default_style death_animation = true, -- animate the pet's death, set to false to feel less guilt + popup = { -- popup options, try changing these if you see a rectangle around the pets + width = "30%", -- can be a string with percentage like "45%" or a number of columns like 45 + winblend = 100, -- winblend value - see :h 'winblend' - only used if avoid_statusline is false + hl = { Normal = "Normal" }, -- hl is only set if avoid_statusline is true, you can put any hl group instead of "Normal" + avoid_statusline = false, -- if winblend is 100 then the popup is invisible and covers the statusline, if that + -- doesn't work for you then set this to true and the popup will use hl and will be spawned above the statusline (hopefully) + } } ``` +### ❔ FAQ - if things don't work +- If the pet is not at the height you desire change the row option +- If you're seeing a square around the pets, try setting avoid_statusline to true and/or winblend to 0. + If this doesn't work then open an issue and I'll try to look into it when I can. ## 🐾 Available pets 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 |