perf: use `vim.ui` instead of `vim.fn`

pull/14/head
Iron-E 2 years ago
parent 7d1d39f915
commit 1933c1d6dc
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -1,21 +1,3 @@
" SUMMARY:
" * Get user input with some `completions`.
" PARAMS:
" * `indicator` => the prompt string.
" * `completions` => the list of completions to provide.
" RETURNS:
" * Input from `input()`.
function! libmodal#_inputWith(indicator, completions)
function! LibmodalCompletionsProvider(argLead, cmdLine, cursorPos) abort closure
return luaeval(
\ 'require("libmodal/src/Prompt").createCompletionsProvider(_A[1])(_A[2], _A[3], _A[4])',
\ [a:completions, a:argLead, a:cmdLine, a:cursorPos]
\)
endfunction
return input(a:indicator, '', 'customlist,LibmodalCompletionsProvider')
endfunction
" SUMMARY:
" * Runs the nvim-libmodal command prompt loop. The function takes an optional
" argument specifying how many times to run (runs until exiting by default).

@ -72,28 +72,28 @@ function _metaPrompt:_inputLoop()
-- clear previous `echo`s.
utils.api.nvim_redraw()
-- define a placeholder for user input
local userInput = ''
-- determine what to do with the input
local function userInputCallback(userInput)
if userInput and string.len(userInput) > 0 then -- The user actually entered something.
self.input:nvimSet(userInput)
self:_executeInstruction(userInput)
else -- indicate we want to leave the prompt
return false
end
return true
end
-- echo the highlighting
vim.api.nvim_command('echohl ' .. self.indicator.hl)
-- set the user input variable
if self._completions then userInput =
vim.fn['libmodal#_inputWith'](self.indicator.str, self._completions)
else userInput =
vim.fn.input(self.indicator)
if self._completions then
vim.api.nvim_command('echo "' .. self.indicator.str .. '"')
return vim.ui.select(self._completions, {}, userInputCallback)
else
return vim.ui.input({prompt = self.indicator.str}, userInputCallback)
end
-- determine what to do with the input
if string.len(userInput) > 0 then -- The user actually entered something.
self.input:nvimSet(userInput)
self:_executeInstruction(userInput)
else -- indicate we want to leave the prompt
return false
end
return true
end
----------------------------

Loading…
Cancel
Save