|
1 | 1 | local M = {}
|
2 | 2 |
|
| 3 | +local async = require("plenary.async") |
| 4 | +local input = async.wrap(function(prompt, default, completion, callback) |
| 5 | + vim.ui.input({ |
| 6 | + prompt = prompt, |
| 7 | + default = default, |
| 8 | + completion = completion, |
| 9 | + }, callback) |
| 10 | +end, 4) |
| 11 | + |
3 | 12 | --- Provides the user with a confirmation
|
4 | 13 | ---@param msg string Prompt to use for confirmation
|
5 | 14 | ---@param options table|nil
|
|
57 | 66 | function M.get_user_input(prompt, opts)
|
58 | 67 | opts = vim.tbl_extend("keep", opts or {}, { strip_spaces = false, separator = ": " })
|
59 | 68 |
|
60 |
| - vim.fn.inputsave() |
61 |
| - |
62 | 69 | if opts.prepend then
|
63 | 70 | vim.defer_fn(function()
|
64 | 71 | vim.api.nvim_input(opts.prepend)
|
65 | 72 | end, 10)
|
66 | 73 | end
|
67 | 74 |
|
68 |
| - local status, result = pcall(vim.fn.input, { |
69 |
| - prompt = ("%s%s"):format(prompt, opts.separator), |
70 |
| - default = opts.default, |
71 |
| - completion = opts.completion, |
72 |
| - cancelreturn = opts.cancel, |
73 |
| - }) |
| 75 | + local result = input(("%s%s"):format(prompt, opts.separator), opts.default, opts.completion) |
74 | 76 |
|
75 |
| - vim.fn.inputrestore() |
76 |
| - if not status then |
| 77 | + if result == "" or result == nil then |
77 | 78 | return nil
|
78 | 79 | end
|
79 | 80 |
|
80 | 81 | if opts.strip_spaces then
|
81 | 82 | result, _ = result:gsub("%s", "-")
|
82 | 83 | end
|
83 | 84 |
|
84 |
| - if result == "" then |
85 |
| - return nil |
86 |
| - end |
87 |
| - |
88 | 85 | return result
|
89 | 86 | end
|
90 | 87 |
|
|
0 commit comments