Skip to content

Commit

Permalink
refactor: pass indent option to buffer constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
topaxi committed Apr 14, 2023
1 parent da9517a commit 5e72153
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
19 changes: 9 additions & 10 deletions lua/gh-actions/ui/buffer.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
local Config = require('gh-actions.config')

---@class TextSegment
---@field str string
---@field hl string|nil

---@alias Line TextSegment[]

---@class Buffer
---@field private _lines Line[]
---@field protected _lines Line[]
---@field protected _indent number
local Buffer = {
ns = vim.api.nvim_create_namespace('gh-actions'),
}

function Buffer.new()
---@param opts? { indent?: integer }
function Buffer.new(opts)
opts = opts or {}

local self = setmetatable({}, {
__index = Buffer,
})

self._lines = {}
self._indent = opts.indent or 2

return self
end
Expand All @@ -28,11 +31,7 @@ function Buffer:append_line(line, opts)
opts = opts or {}

if opts.indent then
table.insert(
line,
1,
{ str = string.rep(' ', opts.indent * Config.options.indent) }
)
table.insert(line, 1, { str = string.rep(' ', opts.indent * self._indent) })
end

table.insert(self._lines, line)
Expand All @@ -53,7 +52,7 @@ function Buffer:append(str, hl, opts)
local line = str

if opts.indent then
line = string.rep(' ', opts.indent * Config.options.indent) .. line
line = string.rep(' ', opts.indent * self._indent) .. line
end

table.insert(self._lines[#self._lines], { str = line, hl = hl })
Expand Down
9 changes: 5 additions & 4 deletions lua/gh-actions/ui/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ local GhActionsRender = {
locations = {},
}

setmetatable(GhActionsRender, { __index = Buffer })

---@param run { status: string, conclusion: string }
---@return string
local function get_workflow_run_icon(run)
Expand Down Expand Up @@ -54,10 +56,9 @@ end
---@param store { get_state: fun(): GhActionsState }
---@return GhActionsRender
function GhActionsRender.new(store)
local self = setmetatable(
{},
{ __index = setmetatable(GhActionsRender, { __index = Buffer }) }
)
local self = setmetatable(Buffer.new { indent = Config.options.indent }, {
__index = GhActionsRender,
})
---@cast self GhActionsRender

self.store = store
Expand Down

0 comments on commit 5e72153

Please sign in to comment.