chore(build): streaming stdout (#511)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham
2024-09-04 00:21:41 -04:00
committed by GitHub
parent 1e43122cac
commit b48b6b7afd
2 changed files with 19 additions and 3 deletions

View File

@@ -66,9 +66,24 @@ M.build = function(opts)
error("Unsupported operating system: " .. os_name, 2)
end
local job = vim.system(cmd, { text = true }):wait()
return vim.tbl_contains({ 0 }, job.code) and true or false
---@type integer
local code
vim.system(cmd, {
text = true,
stdout = function(_, data)
if data then vim.schedule(function() vim.api.nvim_echo({ { data, "Normal" } }, false, {}) end) end
end,
stderr = function(err, _)
if err then vim.schedule(function() vim.api.nvim_echo({ { err, "ErrorMsg" } }, false, {}) end) end
end,
}, function(obj)
if vim.tbl_contains({ 0 }, obj.code) then
code = obj.code
else
vim.api.nvim_echo({ { "Build failed with exit code: " .. obj.code, "ErrorMsg" } }, false, {})
end
end)
return code
end
---@param question? string