Skip to content

Commit

Permalink
multiprocess: use 'io.write' instead of 'uv.pipe:write'
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Dec 13, 2021
1 parent c614b62 commit 4a013fd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lua/fzf-lua/libuv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ M.spawn_stdio = function(opts, fn_transform, fn_preprocess)
end

local function pipe_open(pipename)
if not pipename then return end
local fd = uv.fs_open(pipename, "w", -1)
if type(fd) ~= 'number' then
exit(1, ("error opening '%s': %s\n"):format(pipename, fd))
Expand Down Expand Up @@ -332,8 +333,11 @@ M.spawn_stdio = function(opts, fn_transform, fn_preprocess)
end

stderr = pipe_open(opts.stderr or "/dev/stderr")
stdout = pipe_open(opts.stdout or "/dev/stdout")
assert(stderr and stdout)

-- /dev/stdout seems to create issues on MacOS (#248, #251)
-- do not use a pipe unless use specifically requests it
-- instead we use 'io.write'
stdout = pipe_open(opts.stdout)

local on_finish = opts.on_finish or
function(code)
Expand All @@ -344,7 +348,12 @@ M.spawn_stdio = function(opts, fn_transform, fn_preprocess)

local on_write = opts.on_write or
function(data, cb)
pipe_write(stdout, data, cb)
if stdout then
pipe_write(stdout, data, cb)
else
io.write(data)
cb(nil)
end
end

local on_err = opts.on_err or
Expand Down

0 comments on commit 4a013fd

Please # to comment.