4747
4848--- @param opts { cwd : string , cmd : string | table , env : table ?, cb_finish : function ,
4949--- cb_write: function?, cb_write_lines: function?, cb_err: function, cb_pid: function,
50- --- fn_transform: function?, EOL: string?, process1: boolean ?, profiler : boolean?,
51- --- use_queue: boolean?}
50+ --- fn_transform: function?, EOL: string?, EOL_data: string ?, process1 : boolean?,
51+ --- profiler: boolean?, use_queue: boolean?}
5252--- @param fn_transform function ?
5353--- @param fn_done function ?
5454--- @return uv.uv_process_t proc
5555--- @return integer pid
5656M .spawn = function (opts , fn_transform , fn_done )
5757 local EOL = opts .EOL or " \n "
58+ local EOL_data = type (opts .cmd ) == " string"
59+ -- fd -0|--print0
60+ -- rg -0|--null
61+ -- grep -Z|--null
62+ -- find . -print0
63+ and (opts .cmd :match (" %s%-0" )
64+ or opts .cmd :match (" %s%-?%-print0" ) -- -print0|--print0
65+ or opts .cmd :match (" %s%-%-null" )
66+ or opts .cmd :match (" %s%-Z" ))
67+ and " \0 " or " \n "
5868 local output_pipe = assert (uv .new_pipe (false ))
5969 local error_pipe = assert (uv .new_pipe (false ))
6070 local write_cb_count , read_cb_count = 0 , 0
@@ -176,7 +186,7 @@ M.spawn = function(opts, fn_transform, fn_done)
176186 local ret = {}
177187 local start_idx = 1
178188 repeat
179- local nl_idx = data :find (" \n " , start_idx , true )
189+ local nl_idx = data :find (EOL_data , start_idx , true )
180190 if nl_idx then
181191 local cr = data :byte (nl_idx - 1 , nl_idx - 1 ) == 13 -- \r
182192 local line = data :sub (start_idx , nl_idx - (cr and 2 or 1 ))
378388--- @param opts table
379389--- @return uv.uv_process_t , integer
380390M .spawn_stdio = function (opts )
381- local EOL = opts .multiline and " \0 " or " \n "
382-
383391 -- stdin/stdout are already buffered, not stderr. This means
384392 -- that every character is flushed immediately which caused
385393 -- rendering issues on Mac (#316, #287) and Linux (#414)
@@ -397,6 +405,9 @@ M.spawn_stdio = function(opts)
397405 -- setup global vars
398406 for k , v in pairs (opts .g or {}) do _G [k ] = v end
399407
408+ --- @diagnostic disable-next-line : undefined-field
409+ local EOL = _G ._EOL or opts .multiline and " \0 " or " \n "
410+
400411 -- Requiring make_entry will create the pseudo `_G.FzfLua` global
401412 -- Must be called after global vars are created or devicons will
402413 -- err with "fzf-lua fatal: '_G._fzf_lua_server', '_G._devicons_path' both nil"
0 commit comments