History

console.lua: cache the command-list

Guido Cella committed 1 year ago

Commit f561efe1 parent d4dc19a1 file · +18 −11Browse files

Unified · Split

player/lua/console.lua+18−11
@@ -112,6 +112,7 @@ local completion_append · 111 unmodified lines
112local path_separator = platform == 'windows' and '\\' or '/'112local path_separator = platform == 'windows' and '\\' or '/'
113local completion_old_line113local completion_old_line
114local completion_old_cursor114local completion_old_cursor
115local commands
115 116
116local selectable_items117local selectable_items
117local matches = {}118local matches = {}
@@ -151,11 +152,18 @@ local function get_margin_x() · 33 unmodified lines
151 return opts.margin_x > -1 and opts.margin_x or mp.get_property_native('osd-margin-x')152 return opts.margin_x > -1 and opts.margin_x or mp.get_property_native('osd-margin-x')
152end153end
153 154
154
155local function get_margin_y()155local function get_margin_y()
156 return opts.margin_y > -1 and opts.margin_y or mp.get_property_native('osd-margin-y')156 return opts.margin_y > -1 and opts.margin_y or mp.get_property_native('osd-margin-y')
157end157end
158 158
159local function get_commands()
160 if not commands then
161 commands = mp.get_property_native('command-list')
162 end
163
164 return commands
165end
166
159 167
160-- Naive helper function to find the next UTF-8 character in 'str' after 'pos'168-- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
161-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.169-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
@@ -1017,14 +1025,13 @@ local function maybe_exit() · 855 unmodified lines
1017end1025end
1018 1026
1019local function help_command(param)1027local function help_command(param)
1020 local cmdlist = mp.get_property_native('command-list')1028 table.sort(get_commands(), function(c1, c2)
1021 table.sort(cmdlist, function(c1, c2)
1022 return c1.name < c2.name1029 return c1.name < c2.name
1023 end)1030 end)
1024 local output = ''1031 local output = ''
1025 if param == '' then1032 if param == '' then
1026 output = 'Available commands:\n'1033 output = 'Available commands:\n'
1027 for _, cmd in ipairs(cmdlist) do1034 for _, cmd in ipairs(get_commands()) do
1028 output = output .. ' ' .. cmd.name1035 output = output .. ' ' .. cmd.name
1029 end1036 end
1030 output = output .. '\n'1037 output = output .. '\n'
@@ -1032,7 +1039,7 @@ local function help_command(param) · 1 unmodified line
1032 output = output .. "ESC or Ctrl+d exits the console.\n"1039 output = output .. "ESC or Ctrl+d exits the console.\n"
1033 else1040 else
1034 local cmd = nil1041 local cmd = nil
1035 for _, curcmd in ipairs(cmdlist) do1042 for _, curcmd in ipairs(get_commands()) do
1036 if curcmd.name:find(param, 1, true) then1043 if curcmd.name:find(param, 1, true) then
1037 cmd = curcmd1044 cmd = curcmd
1038 if curcmd.name == param then1045 if curcmd.name == param then
@@ -1410,12 +1417,12 @@ local function text_input(info) · 371 unmodified lines
1410end1417end
1411 1418
1412local function command_list()1419local function command_list()
1413 local commands = {}1420 local cmds = {}
1414 for i, command in ipairs(mp.get_property_native('command-list')) do1421 for i, command in ipairs(get_commands()) do
1415 commands[i] = command.name1422 cmds[i] = command.name
1416 end1423 end
1417 1424
1418 return commands1425 return cmds
1419end1426end
1420 1427
1421local function property_list()1428local function property_list()
@@ -1493,7 +1500,7 @@ local function list_option_value_list(option) · 71 unmodified lines
1493end1500end
1494 1501
1495local function has_file_argument(candidate_command)1502local function has_file_argument(candidate_command)
1496 for _, command in pairs(mp.get_property_native('command-list')) do1503 for _, command in pairs(get_commands()) do
1497 if command.name == candidate_command then1504 if command.name == candidate_command then
1498 return command.args[1] and1505 return command.args[1] and
1499 (command.args[1].name == 'filename' or command.args[1].name == 'url')1506 (command.args[1].name == 'filename' or command.args[1].name == 'url')
@@ -1587,7 +1594,7 @@ local function command_flags_at_2nd_argument_list(command) · 87 unmodified lines
1587end1594end
1588 1595
1589local function handle_flags(command, arg_index, flags)1596local function handle_flags(command, arg_index, flags)
1590 for _, cmd in pairs(mp.get_property_native('command-list')) do1597 for _, cmd in pairs(get_commands()) do
1591 if cmd.name == command then1598 if cmd.name == command then
1592 if cmd.args[arg_index] and cmd.args[arg_index].type == 'Flags' then1599 if cmd.args[arg_index] and cmd.args[arg_index].type == 'Flags' then
1593 break1600 break

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