feat: implement public API and plugin commands
Rewrite init.lua to expose setup(), run(), stop(), and toggle() that
coordinate across config, runner, window, and indicator modules. Replace
the placeholder SayHello command in plugin/watchexec.lua with keymaps
(<Leader>wx{t,s,r}), :WatchexecRun/:WatchexecStop/:WatchexecToggle
commands, VimLeavePre cleanup, and VimResized auto-resize.
This commit is contained in:
+59
-7
@@ -1,15 +1,67 @@
|
||||
---@brief [[
|
||||
--- watchexec.nvim integrates the watchexec CLI into Neovim, providing a
|
||||
--- floating or split window to display file-watching command output.
|
||||
---@brief ]]
|
||||
|
||||
local config = require("watchexec.config")
|
||||
local runner = require("watchexec.runner")
|
||||
local window = require("watchexec.window")
|
||||
local indicator = require("watchexec.indicator")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.config = {
|
||||
greeting = "Hello from my plugin",
|
||||
}
|
||||
|
||||
---Merge user-provided options into the config and resolve the watchexec binary.
|
||||
---Call this in your init.lua: `require("watchexec").setup({...})`.
|
||||
---@param opts? watchexec.Config
|
||||
function M.setup(opts)
|
||||
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
|
||||
config.setup(opts)
|
||||
end
|
||||
|
||||
function M.say_hello()
|
||||
print(M.config.greeting)
|
||||
---Start a watchexec process for the given command.
|
||||
---Stops any previously running process, opens the output window if hidden,
|
||||
---then spawns the child process.
|
||||
---@param command string Shell command to run under watchexec
|
||||
function M.run(command)
|
||||
if runner.is_running() then
|
||||
runner.stop()
|
||||
end
|
||||
|
||||
window.clear()
|
||||
|
||||
if not window.is_visible() then
|
||||
window.open()
|
||||
end
|
||||
|
||||
runner.start(command)
|
||||
indicator.refresh()
|
||||
end
|
||||
|
||||
---Stop the currently running watchexec process.
|
||||
function M.stop()
|
||||
runner.stop()
|
||||
window.clear()
|
||||
indicator.reset()
|
||||
indicator.refresh()
|
||||
end
|
||||
|
||||
---Toggle the watchexec output window.
|
||||
---If no process is running and window is hidden, opens with a placeholder.
|
||||
---If no process is running and window is visible, closes it.
|
||||
---If running and visible, hides the window.
|
||||
---If running but hidden, shows the window.
|
||||
function M.toggle()
|
||||
if not runner.is_running() then
|
||||
if window.is_visible() then
|
||||
window.close()
|
||||
else
|
||||
window.clear()
|
||||
window.open()
|
||||
end
|
||||
elseif window.is_visible() then
|
||||
window.toggle()
|
||||
else
|
||||
window.open()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user