console.lua: add a keep_open flag to mp.input
With input.select this allows building nested submenus without the flicker of console quickly closing and reopening, and also doing multiple selections, to e.g. cycle through different values of a property, or increase a property multiple times. With input.get this is used to change the default behavior to closing by default on submit. It was argued by avih that this is more useful, and indeed Github code search shows that everybody is calling input.terminate() unconditionally on submit, so the impact of the change should be low, and restoring the old behavior is as easy as passing keep_open = true, which is just ignored in older mpv versions.
This commit is contained in:
1 parent
7dd5154971
commit
996c098725
4 files changed
+17
-9
No files matched your search
@@ -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
|
||||
+8
-6
@@ -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:
|
||||
|
||||
|
||||
@@ -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] = {}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user