diff --git a/lua/sg/system.lua b/lua/sg/system.lua index 880461c4..7109a9c8 100644 --- a/lua/sg/system.lua +++ b/lua/sg/system.lua @@ -2,6 +2,6 @@ local async = require "plenary.async" return { async = async.wrap(function(a, b, c) - return vim.system(a, b, vim.schedule_wrap(c)) + return require("sg.utils").system(a, b, vim.schedule_wrap(c)) end, 3), } diff --git a/lua/sg/utils.lua b/lua/sg/utils.lua index 3ce83f4e..0e069285 100644 --- a/lua/sg/utils.lua +++ b/lua/sg/utils.lua @@ -59,4 +59,22 @@ utils.joinpath = vim.fs.joinpath or function(...) return (table.concat({ ... }, "/"):gsub("//+", "/")) end +-- COMPAT(0.10.0) +-- So far only handle stdout, no other items are handled. +-- Probably will break on me unexpectedly. Nice +utils.system = vim.system + or function(cmd, opts, on_exit) + local stdout = "" + opts.stdout_buffered = true + opts.on_stdout = function(_, data) + stdout = stdout .. table.concat(data, "") + end + opts.on_exit = function() + stdout = stdout .. "\n" + on_exit { stdout = stdout, compat = true } + end + + vim.fn.jobstart(cmd, opts) + end + return utils diff --git a/lua/tests/async_compat_spec.lua b/lua/tests/async_compat_spec.lua new file mode 100644 index 00000000..09fd4229 --- /dev/null +++ b/lua/tests/async_compat_spec.lua @@ -0,0 +1,15 @@ +require("plenary.async").tests.add_to_env() + +local system = require "sg.system" + +local eq = assert.are.same + +describe("compat", function() + describe("vim.system", function() + a.it("void functions can call wrapped functions", function() + local obj = system.async({ "echo", "hello" }, { text = true }) + local result = obj.stdout + eq(result, "hello\n") + end) + end) +end)