From b6ea68367e8a616a357ec3f3ca8d808121838267 Mon Sep 17 00:00:00 2001 From: Calvin Bochulak Date: Fri, 24 Mar 2023 07:39:07 -0600 Subject: [PATCH] feat: refactor Portal.Content as a class --- lua/portal/content.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lua/portal/content.lua diff --git a/lua/portal/content.lua b/lua/portal/content.lua new file mode 100644 index 0000000..06190b6 --- /dev/null +++ b/lua/portal/content.lua @@ -0,0 +1,31 @@ +---@class Portal.Content +---@field type string +---@field buffer integer +---@field cursor { row: integer, col: integer } +---@field callback fun(c: Portal.Content) +---@field extra table +local Content = {} +Content.__index = Content + +function Content:new(content) + assert(content.buffer, ("Portal: invalid content.buffer %s"):format(vim.inspect(content.buffer))) + assert( + content.cursor and content.cursor.row and content.cursor.col, + ("Portal: invalid content.cursor %s"):format(vim.inspect(content.cursor)) + ) + assert( + type(content.callback) == "function", + ("Portal: invalid content.callback %s"):format(vim.inspect(content.callback)) + ) + + content.extra = content.extra or {} + setmetatable(content, self) + + return content +end + +function Content:select() + return self.callback(self) +end + +return Content