diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-10 17:47:42 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-10 17:47:42 +0100 |
| commit | 8ee3958d1a0958917ecb3f7481e369bb62e8ddb3 (patch) | |
| tree | 1f6d20fdda804ae77b91548b03c757ffceae2970 /lua | |
| parent | refactor(pets): pets table is now indexed by name (diff) | |
feat(pets): ability to kill pets by name
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets.lua | 9 | ||||
| -rw-r--r-- | lua/pets/commands.lua | 4 |
2 files changed, 12 insertions, 1 deletions
diff --git a/lua/pets.lua b/lua/pets.lua index 1c09146..363f049 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -27,7 +27,14 @@ function M.create_pet(name, type, style) -- TODO: don't allow duplicate names M.pets[pet.name] = pet end --- function M.kill_pet(name) end +function M.kill_pet(name) + if M.pets[name] ~= nil then + M.pets[name]:kill() + M.pets[name] = nil + else + print("Pet name incorrect") + end +end function M.kill_all() for _, pet in pairs(M.pets) do diff --git a/lua/pets/commands.lua b/lua/pets/commands.lua index 71eb4f4..7bf9d8c 100644 --- a/lua/pets/commands.lua +++ b/lua/pets/commands.lua @@ -8,6 +8,10 @@ vim.api.nvim_create_user_command("PetsKillAll", function() pets.kill_all() end, {}) +vim.api.nvim_create_user_command("PetsKill", function(input) + pets.kill_pet(input.args) +end, { nargs = 1 }) + vim.api.nvim_create_user_command("PetsList", function() pets.list() end, {}) |