History

input.lua,defaults.js: don't hardcode mp.input arguments

Pass everything in the tables passed by mp.input callers to console.lua so new flags can be added without modifying these clients. In Lua, callbacks have to be excluded from the argument tables to not make utils.format_json() error, while with JSON.stringify they are automatically omitted.

Guido Cella committed 2 years ago

Commit b3f84641 parent dcd681e2 files · +16 −32Browse files

Showing the changes to player/lua/input.lua (1 of 2 files). Show all

Unified · Split

player/lua/input.lua+14−16
@@ -18,6 +18,18 @@ License along with mpv. If not, see <http://www.gnu.org/licenses/>. · 17 unmodified lines
18local utils = require "mp.utils"18local utils = require "mp.utils"
19local input = {}19local input = {}
20 20
21local function get_non_callbacks(t)
22 local non_callbacks = {}
23
24 for key, value in pairs(t) do
25 if type(value) ~= "function" then
26 non_callbacks[key] = value
27 end
28 end
29
30 return non_callbacks
31end
32
21local function register_event_handler(t)33local function register_event_handler(t)
22 mp.register_script_message("input-event", function (type, args)34 mp.register_script_message("input-event", function (type, args)
23 if t[type] then35 if t[type] then
@@ -38,26 +50,12 @@ end · 14 unmodified lines
38 50
39function input.get(t)51function input.get(t)
40 mp.commandv("script-message-to", "console", "get-input",52 mp.commandv("script-message-to", "console", "get-input",
41 mp.get_script_name(), utils.format_json({53 mp.get_script_name(), utils.format_json(get_non_callbacks(t)))
42 prompt = t.prompt,
43 default_text = t.default_text,
44 cursor_position = t.cursor_position,
45 id = t.id,
46 }))
47 54
48 register_event_handler(t)55 register_event_handler(t)
49end56end
50 57
51function input.select(t)58input.select = input.get
52 mp.commandv("script-message-to", "console", "get-input",
53 mp.get_script_name(), utils.format_json({
54 prompt = t.prompt,
55 items = t.items,
56 default_item = t.default_item,
57 }))
58
59 register_event_handler(t)
60end
61 59
62function input.terminate()60function input.terminate()
63 mp.commandv("script-message-to", "console", "disable")61 mp.commandv("script-message-to", "console", "disable")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t