feat: libuv stdout|stderr stream redirect options (#414)

main
bhagwan 2 years ago
parent 7583b40fde
commit d4ab66551b

@ -346,6 +346,9 @@ M.mt_cmd_wrapper = function(opts)
"argv_expr", "argv_expr",
"cmd", "cmd",
"cwd", "cwd",
"stdout",
"stderr",
"stderr_to_stdout",
"git_dir", "git_dir",
"git_worktree", "git_worktree",
"git_icons", "git_icons",

@ -295,21 +295,26 @@ M.spawn_stdio = function(opts, fn_transform, fn_preprocess)
return fn_loaded return fn_loaded
end end
-- stdin/stdout are already buffered, not stderr this means
-- that every character is flushed immedietely which casued
-- rendering issues on Mac (#316, #287) and Linux (#414)
-- switch 'stderr' stream to 'line' buffering
-- https://www.lua.org/manual/5.2/manual.html#pdf-file%3asetvbuf
io.stderr:setvbuf 'line'
-- redirect 'stderr' to 'stdout' on Macs by default
-- only takes effect if 'opts.stderr' was not set
if opts.stderr_to_stdout == nil and
vim.loop.os_uname().sysname == 'Darwin' then
opts.stderr_to_stdout = true
end
fn_transform = load_fn(fn_transform) fn_transform = load_fn(fn_transform)
fn_preprocess = load_fn(fn_preprocess) fn_preprocess = load_fn(fn_preprocess)
-- if opts.argv_expr and opts.debug then
-- io.stdout:write("[DEBUG]: "..opts.cmd.."\n")
-- end
-- run the preprocessing fn -- run the preprocessing fn
if fn_preprocess then fn_preprocess(opts) end if fn_preprocess then fn_preprocess(opts) end
-- for i=0,8 do
-- io.stdout:write(("%d %s\n"):format(i, vim.v.argv[i]))
-- end
local is_darwin = vim.loop.os_uname().sysname == 'Darwin'
if opts.debug then if opts.debug then
io.stdout:write("[DEBUG]: "..opts.cmd.."\n") io.stdout:write("[DEBUG]: "..opts.cmd.."\n")
@ -360,10 +365,10 @@ M.spawn_stdio = function(opts, fn_transform, fn_preprocess)
end) end)
end end
if opts.stderr then if type(opts.stderr) == 'string' then
stderr = pipe_open(opts.stderr) stderr = pipe_open(opts.stderr)
end end
if opts.stdout then if type(opts.stdout) == 'string' then
stdout = pipe_open(opts.stdout) stdout = pipe_open(opts.stdout)
end end
@ -396,10 +401,8 @@ M.spawn_stdio = function(opts, fn_transform, fn_preprocess)
function(data) function(data)
if stderr then if stderr then
pipe_write(stderr, data) pipe_write(stderr, data)
else elseif opts.stderr ~= false then
if is_darwin then if opts.stderr_to_stdout then
-- for some reason io:stderr causes
-- weird rendering issues on Mac (#316, #287)
io.stdout:write(data) io.stdout:write(data)
else else
io.stderr:write(data) io.stderr:write(data)

Loading…
Cancel
Save