How to write to stdin of a Job from an Autocmd?
kothavade opened this issue · comments
Hey, first time using Plenary, and struggling a bit with understanding how to use plenary.job
.
For context, I have a long running network process running as a plenary.job
wrapped in plenary.async
. I'd like to execute functions based on its stdout as it comes, and independently send data to it through stdin whenever an autocmd fires.
Is it possible to write data to its stdin based on the callback of an autocmd? If so, how can that be done?
Here's an abbreviated version of the code I have so far, which seems to be functioning as expected for the stdout part.
Code
local autocmd = vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter", "TextChanged" }, {
pattern = { "*.typ" },
callback = function(ev)
-- Write to stdin from this callback
end,
})
local async_job = Async.void(function()
local job = Job:new({
command = "websocat",
args = { ... },
writer = -- Not sure what could go here
on_stdout = function(_, data)
vim.schedule(function()
print(vim.fn.json_decode(data))
end)
end,
})
job:start()
end)
Thanks for the help!
Never mind, seems like I was overthinking this and Job:send()
is what I want. Thanks for the library!