Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

neovim/lua/bugabinga/cmdline/state.lua

Raw
local table = require 'std.table'

local M = {}

local function new(content, pos, firstc, prompt, indent, level)
  vim.validate('content', content, 'table')
  vim.validate('pos', pos, 'number')
  vim.validate('firstc', firstc, 'string')
  vim.validate('prompt', prompt, 'string')
  vim.validate('indent', indent, 'number')
  vim.validate('level', level, 'number')
  return setmetatable({
    content = content,
    pos = pos,
    firstc = firstc,
    prompt = prompt,
    indent = indent,
    level = level,
  }, { __index = M })
end

local function text(self)
  local parts = {}
  for _, chunk in ipairs(self.content) do
    table.insert(parts, chunk[2])
  end
  return table.concat(parts)
end

local function cursor_byte(self)
  return self.pos
end

local function is_search(self)
  return self.firstc == '/' or self.firstc == '?'
end

local function is_input(self)
  return self.prompt ~= nil and self.prompt ~= ''
end

M.new = new
M.text = text
M.cursor_byte = cursor_byte
M.is_search = is_search
M.is_input = is_input

return M