robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesfeat(ui): use vim.ui.select for :tselect, z= #3947855ceb314ca

master
751 B23 linesraw
1local M = {}
2
3--- Wait for |vim.ui.select()| and return the selected index. The default vim.ui.select impl
4--- (inputlist()) is synchronous, but this also handles async pickers (fzf-lua, telescope, …).
5---
6--- @param items table Items to choose from.
7--- @param opts table Forwarded to |vim.ui.select()|.
8--- @return integer? # 1-based index of the chosen item, or nil if cancelled/interrupted.
9function M.select_blocking(items, opts)
10  local choice ---@type integer?
11  local done = false
12  vim.ui.select(items, opts or {}, function(_, idx)
13    choice = idx
14    done = true
15  end)
16  -- vim.wait returns false on timeout (math.huge means never) or interrupt (-2).
17  vim.wait(math.huge, function()
18    return done
19  end)
20  return choice
21end
22
23return M