stats.lua: allow keybindings to toggle the display of a specific page

This lets you define bindings like h script-binding
stats/display-page-4-toggle. Requested in #14966.
This commit is contained in:
Guido Cella 2024-10-01 21:47:48 +02:00 committed by Avi Halachmi
parent be814e3753
commit 493cab7efc
3 changed files with 15 additions and 8 deletions

View File

@ -0,0 +1 @@
add `display-page-n-toggle` script bindings to stats.lua, where n is a page number

View File

@ -233,7 +233,7 @@ Additional keys can be configured in ``input.conf`` to display the stats::
And to display a certain page directly::
i script-binding stats/display-page-1
e script-binding stats/display-page-2
h script-binding stats/display-page-4-toggle
Active key bindings page
~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1750,14 +1750,20 @@ mp.add_key_binding(nil, "display-stats", function() process_key_binding(true) en
mp.add_key_binding(nil, "display-stats-toggle", function() process_key_binding(false) end,
{repeatable=false})
-- Single invocation bindings without key, can be used in input.conf to create
-- bindings for a specific page: "e script-binding stats/display-page-2"
for k, _ in pairs(pages) do
mp.add_key_binding(nil, "display-page-" .. k,
function()
curr_page = k
process_key_binding(true)
end, {repeatable=true})
-- Single invocation key bindings for specific pages, e.g.:
-- "e script-binding stats/display-page-2"
mp.add_key_binding(nil, "display-page-" .. k, function()
curr_page = k
process_key_binding(true)
end, {repeatable=true})
-- Key bindings to toggle a specific page, e.g.:
-- "h script-binding stats/display-page-4-toggle".
mp.add_key_binding(nil, "display-page-" .. k .. "-toggle", function()
curr_page = k
process_key_binding(false)
end, {repeatable=true})
end
-- Reprint stats immediately when VO was reconfigured, only when toggled