@ 261105.2

251129.13 · 6ed954164fb1e7a150e2fcc5cc48f671570335bf

fix: fail to resume fzf_live

reading declarations

lua/fzf-lua/core.lua

@@ -218,17 +218,24 @@ M.fzf_live = function(contents, opts)   if not opts then return end   local fzf_field_index = M.fzf_field_index(opts)   local cmd ---@type string-  if type(contents) == "function" and M.can_transform(opts) then-    cmd = shell.stringify_data(-      function(items) return contents(items, opts) end, opts, fzf_field_index)+  local is_fnc = type(contents) == "function"+  if is_fnc and M.can_transform(opts) then+    cmd = shell.stringify_data(function(items) return contents(items, opts) end, opts,+      fzf_field_index)   else     contents = add_query_placeholder(contents)     local mtcmd = shell.stringify_mt(contents, opts)-    cmd = mtcmd and M.expand_query(mtcmd, fzf_field_index)-        or type(contents) == "string" and nop(opts) and M.expand_query(contents, fzf_field_index)-        or shell.stringify(cmd2fnc(contents), opts, fzf_field_index)+    if mtcmd then+      cmd = M.expand_query(mtcmd, fzf_field_index)+    elseif not is_fnc and nop(opts) then+      cmd = M.expand_query(contents, fzf_field_index)+    else+      cmd = shell.stringify(cmd2fnc(contents), opts, fzf_field_index)+      is_fnc = true+    end   end-  M.setup_fzf_live_flags(cmd, opts)+  -- function content require `--bind=start` to fix ctrl-c+resume+  M.setup_fzf_live_flags(cmd, is_fnc, opts)   return M.fzf_wrap(cmd, opts, true) end @@ -1073,8 +1080,9 @@ M.convert_exec_silent_actions = function(opts) end  ---@param command string+---@param bind_start boolean ---@param opts table-M.setup_fzf_live_flags = function(command, opts)+M.setup_fzf_live_flags = function(command, bind_start, opts)   -- query cannot be 'nil'   opts.query = opts.query or "" @@ -1121,11 +1129,10 @@ M.setup_fzf_live_flags = function(command, opts)     if opts.silent_fail ~= false then       reload_command = reload_command .. " || " .. utils.shell_nop()     end-    local query = opts.query and tostring(opts.query) or ""     local action = M.can_transform(opts) and "transform" or "reload"     table.insert(opts._fzf_cli_args, "--bind="       .. libuv.shellescape(string.format("change:+%s:%s", action, reload_command)))-    if opts.exec_empty_query or #query > 0 or type(opts.contents) == "function" then+    if bind_start or opts.exec_empty_query or #opts.query > 0 then       table.insert(opts._fzf_cli_args, "--bind="         .. libuv.shellescape(string.format("start:+%s:%s", action, reload_command)))     end

lua/fzf-lua/make_entry.lua

@@ -224,7 +224,7 @@ M.lgrep = function(s, opts)   elseif opts.silent_fail ~= false then     cmd0 = cmd0 .. " || " .. FzfLua.utils.shell_nop()   end-  if opts.contents or not FzfLua.core.can_transform(opts) then+  if _G._fzf_lua_is_headless or not FzfLua.core.can_transform(opts) then     return cmd0   else     return "reload:" .. cmd0@@ -383,7 +383,7 @@ M.get_grep_cmd = function(opts, search_query, no_esc)   ---@param fzf_field_index string   ---@return string   local expand_query = function(cmd, fzf_field_index)-    if opts.contents and cmd:match("<query>") then+    if _G._fzf_lua_is_headless and cmd:match("<query>") then       return (cmd:gsub("<query>", fzf_field_index))     else       return ("%s %s"):format(cmd, fzf_field_index)

lua/fzf-lua/shell.lua

@@ -265,10 +265,9 @@ M.stringify_mt = function(contents, opts)     -- don't use mt for non-string contents unless multiprocess is explictly set to true   elseif opts.multiprocess ~= true and type(contents) ~= "string" then     return nil-  else-    opts.contents = contents-    return M.wrap_spawn_stdio(filter_opts(opts))   end+  opts.contents = contents+  return M.wrap_spawn_stdio(filter_opts(opts)) end  -- Contents sent to fzf can only be nil or a shell command (string)

tests/api_spec.lua

@@ -266,4 +266,30 @@ T["api"]["events"] = new_set(   } ) +T["api"]["resume"] = new_set({+  parametrize = { { "fzf_exec" }, { "fzf_live" } },+}, {+  function(api)+    helpers.FzfLua[api](child, "echo resume string content",+      { __expect_lines = false, exec_empty_query = true, debug = 1 })+    helpers.FzfLua.resume(child, { __expect_lines = true })++    helpers.FzfLua[api](child, api == "fzf_exec"+      and function(fzf_cb)+        fzf_cb("resume function content")+        fzf_cb(nil)+      end or function(_)+        return function(fzf_cb)+          fzf_cb("resume function content")+          fzf_cb(nil)+        end+      end, {+        __expect_lines = false,+        exec_empty_query = true,+        debug = 1,+      })+    helpers.FzfLua.resume(child, { __expect_lines = true })+  end,+})+ return T

tests/screenshots/tests-api_spec.lua---api---resume---1-+-args-{-'fzf_exec'-}

new file mode 100644@@ -0,0 +1,29 @@+--|---------|---------|---------|---------|---------|---------|----+01|                                                                +02|~                                                               +03|~      ╭─────────────────────────────────────────────────╮      +04|~      │>                                            1/1 │      +05|~      │──────────────────────────────────────────────── │      +06|~      │▌ resume string content                          │      +07|~      │                                                 │      +08|~      │                                                 │      +09|~      │                                                 │      +10|~      │                                                 │      +11|~      │                                                 │      +12|~      │                                                 │      +13|~      │                                                 │      +14|~      │                                                 │      +15|~      │                                                 │      +16|~      │                                                 │      +17|~      │                                                 │      +18|~      │                                                 │      +19|~      │                                                 │      +20|~      │                                                 │      +21|~      │                                                 │      +22|~      ╰─────────────────────────────────────────────────╯      +23|~                                                               +24|[No Name]                                     0,0-1          All+25|                                                                +26|                                                                +27|                                                                +28|-- TERMINAL --                                1,3           All 

tests/screenshots/tests-api_spec.lua---api---resume---1-+-args-{-'fzf_exec'-}-002

new file mode 100644@@ -0,0 +1,29 @@+--|---------|---------|---------|---------|---------|---------|----+01|                                                                +02|~                                                               +03|~      ╭─────────────────────────────────────────────────╮      +04|~      │>                                            1/1 │      +05|~      │──────────────────────────────────────────────── │      +06|~      │▌ resume function content                        │      +07|~      │                                                 │      +08|~      │                                                 │      +09|~      │                                                 │      +10|~      │                                                 │      +11|~      │                                                 │      +12|~      │                                                 │      +13|~      │                                                 │      +14|~      │                                                 │      +15|~      │                                                 │      +16|~      │                                                 │      +17|~      │                                                 │      +18|~      │                                                 │      +19|~      │                                                 │      +20|~      │                                                 │      +21|~      │                                                 │      +22|~      ╰─────────────────────────────────────────────────╯      +23|~                                                               +24|[No Name]                                     0,0-1          All+25|                                                                +26|                                                                +27|                                                                +28|-- TERMINAL --                                1,3           All 

tests/screenshots/tests-api_spec.lua---api---resume---1-+-args-{-'fzf_live'-}

new file mode 100644@@ -0,0 +1,29 @@+--|---------|---------|---------|---------|---------|---------|----+01|                                                                +02|~                                                               +03|~      ╭─────────────────────────────────────────────────╮      +04|~      │>                                            1/1 │      +05|~      │──────────────────────────────────────────────── │      +06|~      │▌ resume string content                          │      +07|~      │                                                 │      +08|~      │                                                 │      +09|~      │                                                 │      +10|~      │                                                 │      +11|~      │                                                 │      +12|~      │                                                 │      +13|~      │                                                 │      +14|~      │                                                 │      +15|~      │                                                 │      +16|~      │                                                 │      +17|~      │                                                 │      +18|~      │                                                 │      +19|~      │                                                 │      +20|~      │                                                 │      +21|~      │                                                 │      +22|~      ╰─────────────────────────────────────────────────╯      +23|~                                                               +24|[No Name]                                     0,0-1          All+25|                                                                +26|                                                                +27|                                                                +28|-- TERMINAL --                                1,3           All 

tests/screenshots/tests-api_spec.lua---api---resume---1-+-args-{-'fzf_live'-}-002

new file mode 100644@@ -0,0 +1,29 @@+--|---------|---------|---------|---------|---------|---------|----+01|                                                                +02|~                                                               +03|~      ╭─────────────────────────────────────────────────╮      +04|~      │>                                            1/1 │      +05|~      │──────────────────────────────────────────────── │      +06|~      │▌ resume function content                        │      +07|~      │                                                 │      +08|~      │                                                 │      +09|~      │                                                 │      +10|~      │                                                 │      +11|~      │                                                 │      +12|~      │                                                 │      +13|~      │                                                 │      +14|~      │                                                 │      +15|~      │                                                 │      +16|~      │                                                 │      +17|~      │                                                 │      +18|~      │                                                 │      +19|~      │                                                 │      +20|~      │                                                 │      +21|~      │                                                 │      +22|~      ╰─────────────────────────────────────────────────╯      +23|~                                                               +24|[No Name]                                     0,0-1          All+25|                                                                +26|                                                                +27|                                                                +28|-- TERMINAL --                                1,3           All