mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 02:50:06 +08:00
chore(format): format code
This commit is contained in:
parent
1d8dbeb8bb
commit
d393df8ada
@ -10,8 +10,6 @@ local M = {}
|
|||||||
|
|
||||||
local uv = vim.loop
|
local uv = vim.loop
|
||||||
|
|
||||||
local logger = require('spacevim.logger').derive('job')
|
|
||||||
|
|
||||||
local _jobs = {}
|
local _jobs = {}
|
||||||
local _jobid = 0
|
local _jobid = 0
|
||||||
|
|
||||||
@ -46,28 +44,28 @@ local function new_job_obj(id, handle, opt, state)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function default_dev() -- {{{
|
local function default_dev() -- {{{
|
||||||
local env = vim.fn.environ()
|
local env = vim.fn.environ()
|
||||||
env['NVIM'] = vim.v.servername
|
env['NVIM'] = vim.v.servername
|
||||||
env['NVIM_LISTEN_ADDRESS'] = nil
|
env['NVIM_LISTEN_ADDRESS'] = nil
|
||||||
env['NVIM_LOG_FILE'] = nil
|
env['NVIM_LOG_FILE'] = nil
|
||||||
env['VIMRUNTIME'] = nil
|
env['VIMRUNTIME'] = nil
|
||||||
return env
|
return env
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
local function setup_env(env, clear_env) -- {{{
|
local function setup_env(env, clear_env) -- {{{
|
||||||
if clear_env then
|
if clear_env then
|
||||||
return env
|
return env
|
||||||
end
|
end
|
||||||
--- @type table<string,string|number>
|
--- @type table<string,string|number>
|
||||||
env = vim.tbl_extend('force', default_dev(), env or {})
|
env = vim.tbl_extend('force', default_dev(), env or {})
|
||||||
|
|
||||||
local renv = {} --- @type string[]
|
local renv = {} --- @type string[]
|
||||||
for k, v in pairs(env) do
|
for k, v in pairs(env) do
|
||||||
renv[#renv + 1] = string.format('%s=%s', k, tostring(v))
|
renv[#renv + 1] = string.format('%s=%s', k, tostring(v))
|
||||||
end
|
end
|
||||||
|
|
||||||
return renv
|
return renv
|
||||||
end
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
@ -207,27 +205,27 @@ function M.start(cmd, opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.send(id, data) -- {{{
|
function M.send(id, data) -- {{{
|
||||||
local jobobj = _jobs['jobid_' .. id]
|
local jobobj = _jobs['jobid_' .. id]
|
||||||
|
|
||||||
if not jobobj then
|
if not jobobj then
|
||||||
error('can not find job:' .. id)
|
error('can not find job:' .. id)
|
||||||
end
|
end
|
||||||
|
|
||||||
local stdin = jobobj.state.stdin
|
local stdin = jobobj.state.stdin
|
||||||
|
|
||||||
if not stdin then
|
if not stdin then
|
||||||
error('no stdin stream for jobid:' .. id)
|
error('no stdin stream for jobid:' .. id)
|
||||||
end
|
end
|
||||||
|
|
||||||
if type(data) == 'table' then
|
if type(data) == 'table' then
|
||||||
for _, v in ipairs(data) do
|
for _, v in ipairs(data) do
|
||||||
stdin:write(v)
|
stdin:write(v)
|
||||||
stdin:write('\n')
|
stdin:write('\n')
|
||||||
end
|
end
|
||||||
elseif type(data) == 'string' then
|
elseif type(data) == 'string' then
|
||||||
stdin:write(data)
|
stdin:write(data)
|
||||||
stdin:write('\n')
|
stdin:write('\n')
|
||||||
elseif data == nil then
|
elseif data == nil then
|
||||||
stdin:write('', function()
|
stdin:write('', function()
|
||||||
stdin:shutdown(function()
|
stdin:shutdown(function()
|
||||||
if stdin then
|
if stdin then
|
||||||
@ -235,7 +233,7 @@ elseif data == nil then
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.chanclose(id, t)
|
function M.chanclose(id, t)
|
||||||
@ -250,7 +248,6 @@ function M.chanclose(id, t)
|
|||||||
if stdin and stdin:is_active() then
|
if stdin and stdin:is_active() then
|
||||||
stdin:close()
|
stdin:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif t == 'stdout' then
|
elseif t == 'stdout' then
|
||||||
elseif t == 'stderr' then
|
elseif t == 'stderr' then
|
||||||
else
|
else
|
||||||
@ -268,5 +265,4 @@ function M.stop(id)
|
|||||||
local handle = jobobj.handle
|
local handle = jobobj.handle
|
||||||
handle:kill(6)
|
handle:kill(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user