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.
68 lines
1.7 KiB
Lua
68 lines
1.7 KiB
Lua
---@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 = {}
|
|
|
|
---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)
|
|
config.setup(opts)
|
|
end
|
|
|
|
---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
|