Skip to content

Commit 3d33d3c

Browse files
committed
refactor: use vim.system instead of vim.fn.jobstart
With `vim.system` we get better type coersion and general support from libuv. Jobstart is primarily meant to be used from vimscript, not lua. Per `:h jobstart` it recommends using `vim.system`. This also makes it easier to handle building the commands list for hurl as now we only have to manage a table. This is the first of a few commits related to pfeiferj#9 and pfeiferj#7.
1 parent 328a96c commit 3d33d3c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lua/hurl/hurl.lua

+13-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function M.hurl(config)
1717
style = "minimal",
1818
border = "rounded",
1919
})
20-
local term = vim.api.nvim_open_term(buf,{})
2120

2221
-- This ensures the window created is closed instead of covering the editor when a split is created
2322
vim.api.nvim_create_autocmd("WinLeave", {
@@ -33,19 +32,25 @@ function M.hurl(config)
3332
})
3433

3534
-- Build arguments list
36-
local hurl_args_t = {}
35+
local hurl_args_t = { "hurl", file, "--include" }
3736
if config.color then
3837
table.insert(hurl_args_t, "--color")
3938
else
4039
table.insert(hurl_args_t, "--no-color")
4140
end
42-
local hurl_args = table.concat(hurl_args_t, " ")
4341

44-
vim.fn.jobstart("hurl " .. file .. " " .. hurl_args, {
45-
width = width,
46-
on_stdout = function(chan, data) vim.api.nvim_chan_send(term,table.concat(data, "\r\n")) end,
47-
on_stderr = function(chan, data) vim.api.nvim_chan_send(term,table.concat(data, "\r\n")) end
48-
})
42+
vim.system(
43+
hurl_args_t,
44+
{ text = true },
45+
---@param cmd SystemCompleted
46+
function(cmd)
47+
local term = vim.api.nvim_open_term(buf, {})
48+
vim.schedule(function()
49+
vim.api.nvim_chan_send(term, table.concat(vim.split(cmd.stdout, "\n"), "\r\n"))
50+
vim.api.nvim_chan_send(term, table.concat(vim.split(cmd.stderr, "\n"), "\r\n"))
51+
end)
52+
end
53+
)
4954
end
5055

5156
return M

0 commit comments

Comments
 (0)