Compare commits

...
Sign in to create a new pull request.

1 commit

View file

@ -1,22 +1,22 @@
local M = {} local M = {}
local subcommands = { 'compile', 'stop', 'clean', 'toggle', 'open', 'status' } local handlers = {
compile = function()
---@param args string
local function dispatch(args)
local subcmd = args ~= '' and args or 'compile'
if subcmd == 'compile' then
require('preview').compile() require('preview').compile()
elseif subcmd == 'stop' then end,
stop = function()
require('preview').stop() require('preview').stop()
elseif subcmd == 'clean' then end,
clean = function()
require('preview').clean() require('preview').clean()
elseif subcmd == 'toggle' then end,
toggle = function()
require('preview').toggle() require('preview').toggle()
elseif subcmd == 'open' then end,
open = function()
require('preview').open() require('preview').open()
elseif subcmd == 'status' then end,
status = function()
local s = require('preview').status() local s = require('preview').status()
local parts = {} local parts = {}
if s.compiling then if s.compiling then
@ -28,6 +28,15 @@ local function dispatch(args)
table.insert(parts, 'watching') table.insert(parts, 'watching')
end end
vim.notify('[preview.nvim]: ' .. table.concat(parts, ', '), vim.log.levels.INFO) vim.notify('[preview.nvim]: ' .. table.concat(parts, ', '), vim.log.levels.INFO)
end,
}
---@param args string
local function dispatch(args)
local subcmd = args ~= '' and args or 'compile'
local handler = handlers[subcmd]
if handler then
handler()
else else
vim.notify('[preview.nvim]: unknown subcommand: ' .. subcmd, vim.log.levels.ERROR) vim.notify('[preview.nvim]: unknown subcommand: ' .. subcmd, vim.log.levels.ERROR)
end end
@ -38,7 +47,7 @@ end
local function complete(lead) local function complete(lead)
return vim.tbl_filter(function(s) return vim.tbl_filter(function(s)
return s:find(lead, 1, true) == 1 return s:find(lead, 1, true) == 1
end, subcommands) end, vim.tbl_keys(handlers))
end end
function M.setup() function M.setup()