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
1818 local utils = require "mp.utils"
1919 local input = {}
2020
21+local 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
31+end
32+
2133 local function register_event_handler(t)
2234 mp.register_script_message("input-event", function (type, args)
2335 if t[type] then
@@ -38,26 +50,12 @@ end · 14 unmodified lines
3850
3951 function input.get(t)
4052 mp.commandv("script-message-to", "console", "get-input",
41− mp.get_script_name(), utils.format_json({
42− prompt = t.prompt,
43− default_text = t.default_text,
44− cursor_position = t.cursor_position,
45− id = t.id,
46− }))
53+ mp.get_script_name(), utils.format_json(get_non_callbacks(t)))
4754
4855 register_event_handler(t)
4956 end
5057
51−function input.select(t)
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)
60−end
58+input.select = input.get
6159
6260 function input.terminate()
6361 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