429 lines · 11.5 KB
---@brief [[
--- glaze.nvim view/UI
--- Lazy.nvim-style floating window with doughnut aesthetic
---@brief ]]

local M = {}

---@type GlazeFloat?
M._float = nil

---@type number?
M._timer = nil

---@type table<string, boolean>
M._expanded = {}

---Line-to-binary mapping for cursor-aware actions.
---@type table<number, string>
M._line_map = {}

local SPINNERS = { "◐", "◓", "◑", "◒" }
local SPINNER_IDX = 1

---Get the binary name under the cursor.
---@return string? name Binary name or nil
function M._get_cursor_binary()
  if not M._float or not M._float:valid() then
    return nil
  end
  local line = vim.api.nvim_win_get_cursor(M._float.win)[1]
  return M._line_map[line]
end

---Open the Glaze UI.
---If already open, just re-render without recreating the window.
function M.open()
  -- If window is already open and valid, just render and return
  if M._float and M._float:valid() then
    M.render()
    return