aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-02-23 13:23:57 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-02-23 13:25:33 +0100
commit3bdde3277b6149727cc7ada1289ba94d48354cc8 (patch)
treea8de9bc092b059b70437549818acf94bdfbd3a69 /lua
parentrefactor: state variables to module level (diff)
fix: crash when using `:only` or `:checkhealth`
safe call for image:display() and if something goes wrong puts pets in hidden state. Pets need to be unhidden via `:PetsHideToggle`. Related to #17
Diffstat (limited to 'lua')
-rw-r--r--lua/pets/animations.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua
index a330cec..1b9d93d 100644
--- a/lua/pets/animations.lua
+++ b/lua/pets/animations.lua
@@ -102,7 +102,6 @@ end
-- @function called on every tick from the timer, go to the next frame
function M.Animation:next_frame()
self.frame_counter = self.frame_counter + 1
-
-- pouplate the buffer with spaces to avoid image distortion
if self.popup.bufnr == nil or not vim.api.nvim_buf_is_valid(self.popup.bufnr) then
return
@@ -124,7 +123,15 @@ function M.Animation:next_frame()
-- frames contains the images for every action
local image = self.frames[self.current_action][self.frame_counter]
M.Animation.set_next_col(self)
- image:display(self.row, self.col, self.popup.bufnr, {})
+ local ok = pcall(image.display, image, self.row, self.col, self.popup.bufnr, {})
+ if not ok then
+ require("pets").hidden = true
+ self:stop()
+ if self.popup then
+ self.popup:unmount()
+ end
+ utils.warning("Something went wrong, pets are hidden")
+ end
self.current_image = image
end