Skip to content

Commit

Permalink
feat: refactor Portal.Content as a class
Browse files Browse the repository at this point in the history
  • Loading branch information
cbochs committed Mar 24, 2023
1 parent 9c36c9e commit b6ea683
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lua/portal/content.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b6ea683

Please sign in to comment.