diff --git a/DOCS/interface-changes/mp.input.txt b/DOCS/interface-changes/mp.input.txt new file mode 100644 index 0000000000..b6a1119b6d --- /dev/null +++ b/DOCS/interface-changes/mp.input.txt @@ -0,0 +1,2 @@ +add `keep_open` flag to `mp.input.get()` and `mp.input.select()` +`mp.input.get()` now closes automatically on submit, pass `keep_open = true` to restore the old behavior diff --git a/DOCS/man/lua.rst b/DOCS/man/lua.rst index 51f684c4f9..bb883ced18 100644 --- a/DOCS/man/lua.rst +++ b/DOCS/man/lua.rst @@ -926,9 +926,10 @@ REPL. ``submit`` A callback invoked when the user presses Enter. The first argument is - the text in the console. You can close the console from within the - callback by calling ``input.terminate()``. If you don't, the console - stays open and the user can input more text. + the text in the console. + + ``keep_open`` + Whether to keep the console open on submit. Defaults to ``false``. ``opened`` A callback invoked when the console is shown. This can be used to @@ -1013,9 +1014,10 @@ REPL. ``submit`` The callback invoked when the user presses Enter. The first argument is - the 1-based index of the selected item. Unlike with ``input.get()``, the - console is automatically closed on submit without having to call - ``input.terminate()``. + the 1-based index of the selected item. + + ``keep_open`` + Whether to keep the console open on submit. Defaults to ``false``. Example: diff --git a/player/lua/console.lua b/player/lua/console.lua index b64b54f0a9..2a6a8d3863 100644 --- a/player/lua/console.lua +++ b/player/lua/console.lua @@ -104,6 +104,7 @@ local dont_bind_up_down = false local overlay = mp.create_osd_overlay('ass-events') local global_margins = { t = 0, b = 0 } local input_caller +local keep_open = false local completion_buffer = {} local selected_completion_index @@ -1093,7 +1094,6 @@ local function submit() mp.commandv('script-message-to', input_caller, 'input-event', 'submit', utils.format_json({matches[selected_match].index})) end - set_active(false) elseif input_caller then mp.commandv('script-message-to', input_caller, 'input-event', 'submit', utils.format_json({line})) @@ -1116,7 +1116,11 @@ local function submit() history_add(line) end - clear() + if input_caller and not keep_open then + set_active(false) + elseif not selectable_items then + clear() + end end local function determine_hovered_item() @@ -2107,6 +2111,7 @@ mp.register_script_message('get-input', function (script_name, args) line = args.default_text or '' cursor = args.cursor_position or line:len() + 1 id = args.id or script_name .. prompt + keep_open = args.keep_open dont_bind_up_down = args.dont_bind_up_down if histories[id] == nil then histories[id] = {} diff --git a/player/lua/stats.lua b/player/lua/stats.lua index dd3bb24ce2..c8d74b2f5a 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -1562,7 +1562,6 @@ local function filter_bindings() display_timer:resume() end end, - submit = input.terminate, closed = function () searched_text = nil if display_timer:is_enabled() then