Get TelescopePrompt buffer in entry_maker

I am trying to write an entry maker function for presenting some files. I am using a similar approach as the telescope file browser entry maker, and presenting files with size and dates stats. The code is supposed to dynamically find the Telescope prompt buffer width and determine width of display items based on that.

The trouble seems to arise with this little snippet:

local get_fb_prompt = function()
  local prompt_bufnr = vim.tbl_filter(function(b)
    return vim.bo[b].filetype == "TelescopePrompt"
  end, vim.api.nvim_list_bufs())
  -- vim.ui.{input, select} might be telescope pickers
  if #prompt_bufnr > 1 then
    for _, buf in ipairs(prompt_bufnr) do
      local current_picker = action_state.get_current_picker(prompt_bufnr)
      if current_picker.finder._browse_files then
        prompt_bufnr = buf
        break
      end
    end
  else
    prompt_bufnr = prompt_bufnr[1]
  end
  return prompt_bufnr
end

Which is then used as:

local make_entry = function()
  local prompt_bufnr = get_fb_prompt()
  local status = state.get_status(prompt_bufnr)
  local total_file_width = vim.api.nvim_win_get_width(status.results_win)
    - #status.picker.selection_caret
    - (opts.disable_devicons and 0 or 1)

  ...
end

However, the get_fb_prompt function seems to always return nil. For instance, having a single lua buffer open, and the output of print(vim.bo[b].filetype) in the first anonymous function of get_fb_prompt is:

"lua"
""

Seems like the filetype for Telescope prompt is not set at BufEnter but sometime after, according to this post. So, what seems to go wrong in this function and how can I get the Telescope prompt width?

You’ll probably have better luck asking in Telescope’s gitter community: nvim-telescope/community - Gitter