From 4128e340c5779763dd809b2242e1ccea456b20f0 Mon Sep 17 00:00:00 2001 From: Giuseppe Gadola Date: Fri, 10 Feb 2023 13:32:41 +0100 Subject: feat(commands): added the list pets command --- lua/pets.lua | 8 +++++++- lua/pets/commands.lua | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/pets.lua b/lua/pets.lua index ed827db..b76df2e 100644 --- a/lua/pets.lua +++ b/lua/pets.lua @@ -23,7 +23,7 @@ function M.setup(options) end -- create a Pet object and add it to the pets table -function M.create_pet(name, type, style) +function M.create_pet(name, type, style) -- TODO: don't allow duplicate names local pet = require("pets.pet").Pet.new(name, type, style) pet:animate() table.insert(M.pets, pet) @@ -37,4 +37,10 @@ function M.kill_all() end end +function M.list() + for _, pet in pairs(M.pets) do + print(pet.name) + end +end + return M diff --git a/lua/pets/commands.lua b/lua/pets/commands.lua index 8c521cd..71eb4f4 100644 --- a/lua/pets/commands.lua +++ b/lua/pets/commands.lua @@ -1,9 +1,13 @@ local pets = require("pets") vim.api.nvim_create_user_command("PetsNew", function(input) - pets.create_pet(input.args, "cat", "brown") + pets.create_pet(input.args, "cat", "light_grey") end, { nargs = 1 }) vim.api.nvim_create_user_command("PetsKillAll", function() pets.kill_all() end, {}) + +vim.api.nvim_create_user_command("PetsList", function() + pets.list() +end, {}) -- cgit v1.3-2-g11bf