mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 15:19:12 +08:00
perf(job): use table for job stdout/stderr data
This commit is contained in:
parent
cfc0d2d6d4
commit
b5d6e1cb5f
@ -35,7 +35,9 @@ function M.start(cmd, opts)
|
|||||||
-- :call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}'])
|
-- :call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}'])
|
||||||
command = shell[1]
|
command = shell[1]
|
||||||
argv = vim.list_slice(shell, 2)
|
argv = vim.list_slice(shell, 2)
|
||||||
for _, v in ipairs(shellcmdflag) do table.insert(argv, v) end
|
for _, v in ipairs(shellcmdflag) do
|
||||||
|
table.insert(argv, v)
|
||||||
|
end
|
||||||
table.insert(argv, cmd)
|
table.insert(argv, cmd)
|
||||||
elseif type(cmd) == 'table' then
|
elseif type(cmd) == 'table' then
|
||||||
command = cmd[1]
|
command = cmd[1]
|
||||||
@ -66,7 +68,8 @@ function M.start(cmd, opts)
|
|||||||
if opts.on_stdout then
|
if opts.on_stdout then
|
||||||
uv.read_start(stdout, function(err, data)
|
uv.read_start(stdout, function(err, data)
|
||||||
if data then
|
if data then
|
||||||
opts.on_stdout(current_id, data, 'stdout')
|
data = data:gsub('\r', '')
|
||||||
|
opts.on_stdout(current_id, vim.split(data, '\n'), 'stdout')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -74,7 +77,8 @@ function M.start(cmd, opts)
|
|||||||
if opts.on_stderr then
|
if opts.on_stderr then
|
||||||
uv.read_start(stderr, function(err, data)
|
uv.read_start(stderr, function(err, data)
|
||||||
if data then
|
if data then
|
||||||
opts.on_stderr(current_id, data, 'stderr')
|
data = data:gsub('\r', '')
|
||||||
|
opts.on_stderr(current_id, vim.split(data, '\n'), 'stderr')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
local job = require('spacevim.api.job')
|
local job = require('spacevim.api.job')
|
||||||
|
|
||||||
local jobid = job.start({ 'rg', 'wsdjeg', '.' }, {
|
local jobid = job.start('echo 1', {
|
||||||
on_stdout = function(id, data, event)
|
on_stdout = function(id, data, event)
|
||||||
vim.print(id)
|
vim.print(id)
|
||||||
vim.print(data)
|
vim.print(vim.inspect(data))
|
||||||
vim.print(event)
|
vim.print(event)
|
||||||
end,
|
end,
|
||||||
on_stderr = function(id, data, event)
|
on_stderr = function(id, data, event)
|
||||||
vim.print(id)
|
vim.print(id)
|
||||||
vim.print(data)
|
vim.print(vim.inspect(data))
|
||||||
vim.print(event)
|
vim.print(event)
|
||||||
end,
|
end,
|
||||||
on_exit = function(id, code, signal)
|
on_exit = function(id, code, signal)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user