aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-02-10 19:25:40 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-02-10 19:25:40 +0100
commit07cee1eab7cf479f36b483e7d31173b34b59bab3 (patch)
tree6c10ea70a0d0b56be93542f22559d4b0d0a58a79 /lua
parentchore: removed tests directory (diff)
feat(pets): don't allow duplicate names
Diffstat (limited to 'lua')
-rw-r--r--lua/pets.lua8
1 files changed, 6 insertions, 2 deletions
diff --git a/lua/pets.lua b/lua/pets.lua
index 363f049..7c7097f 100644
--- a/lua/pets.lua
+++ b/lua/pets.lua
@@ -21,7 +21,11 @@ function M.setup(options)
end
-- create a Pet object and add it to the pets table
-function M.create_pet(name, type, style) -- TODO: don't allow duplicate names
+function M.create_pet(name, type, style)
+ if M.pets[name] ~= nil then
+ vim.api.nvim_err_writeln("Name already in use")
+ return
+ end
local pet = require("pets.pet").Pet.new(name, type, style, M.options.row, M.options.col)
pet:animate()
M.pets[pet.name] = pet
@@ -32,7 +36,7 @@ function M.kill_pet(name)
M.pets[name]:kill()
M.pets[name] = nil
else
- print("Pet name incorrect")
+ vim.api.nvim_err_writeln("Pet name not found")
end
end