summaryrefslogtreecommitdiffstats
path: root/player/lua/input.lua
diff options
context:
space:
mode:
Diffstat (limited to 'player/lua/input.lua')
-rw-r--r--player/lua/input.lua38
1 files changed, 26 insertions, 12 deletions
diff --git a/player/lua/input.lua b/player/lua/input.lua
index 24283e4086..3c1584b2ef 100644
--- a/player/lua/input.lua
+++ b/player/lua/input.lua
@@ -18,18 +18,11 @@ License along with mpv. If not, see <http://www.gnu.org/licenses/>.
local utils = require "mp.utils"
local input = {}
-function input.get(t)
- mp.commandv("script-message-to", "console", "get-input",
- mp.get_script_name(), utils.format_json({
- prompt = t.prompt,
- default_text = t.default_text,
- cursor_position = t.cursor_position,
- id = t.id,
- }))
-
- mp.register_script_message("input-event", function (type, text, cursor_position)
+local function register_event_handler(t)
+ mp.register_script_message("input-event", function (type, args)
if t[type] then
- local suggestions, completion_start_position = t[type](text, cursor_position)
+ local suggestions, completion_start_position =
+ t[type](unpack(utils.parse_json(args or "") or {}))
if type == "complete" and suggestions then
mp.commandv("script-message-to", "console", "complete",
@@ -41,8 +34,29 @@ function input.get(t)
mp.unregister_script_message("input-event")
end
end)
+end
+
+function input.get(t)
+ mp.commandv("script-message-to", "console", "get-input",
+ mp.get_script_name(), utils.format_json({
+ prompt = t.prompt,
+ default_text = t.default_text,
+ cursor_position = t.cursor_position,
+ id = t.id,
+ }))
+
+ register_event_handler(t)
+end
+
+function input.select(t)
+ mp.commandv("script-message-to", "console", "get-input",
+ mp.get_script_name(), utils.format_json({
+ prompt = t.prompt,
+ items = t.items,
+ default_item = t.default_item,
+ }))
- return true
+ register_event_handler(t)
end
function input.terminate()