155 lines · 3.8 KB
---@brief [[
--- glaze.nvim text rendering (based on lazy.nvim)
--- Handles buffered text with highlight segments
---@brief ]]

local M = {}

---@class GlazeTextSegment
---@field str string
---@field hl? string|GlazeExtmark

---@class GlazeExtmark
---@field hl_group? string
---@field col? number
---@field end_col? number
---@field virt_text? table
---@field virt_text_win_col? number

---@class GlazeText
---@field _lines GlazeTextSegment[][]
---@field padding number
---@field wrap number
local Text = {}

function Text.new()
  local self = setmetatable({}, { __index = Text })
  self._lines = {}
  self.padding = 2
  self.wrap = 80
  return self
end

---@param str string
---@param hl? string|GlazeExtmark
---@param opts? { indent?: number, wrap?: boolean }
---@return GlazeText
function Text:append(str, hl, opts)
  opts = opts or {}
  if #self._lines == 0 then
    self:nl()