From 493cab7efc1d80bb780d6eacffb316e7f5313154 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Tue, 1 Oct 2024 21:47:48 +0200 Subject: [PATCH] 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. --- .../interface-changes/display-page-toggle.txt | 1 + DOCS/man/stats.rst | 2 +- player/lua/stats.lua | 20 ++++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 DOCS/interface-changes/display-page-toggle.txt diff --git a/DOCS/interface-changes/display-page-toggle.txt b/DOCS/interface-changes/display-page-toggle.txt new file mode 100644 index 0000000000..0352821074 --- /dev/null +++ b/DOCS/interface-changes/display-page-toggle.txt @@ -0,0 +1 @@ +add `display-page-n-toggle` script bindings to stats.lua, where n is a page number diff --git a/DOCS/man/stats.rst b/DOCS/man/stats.rst index 0e42f44496..4d22f36ff3 100644 --- a/DOCS/man/stats.rst +++ b/DOCS/man/stats.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 2d529e8858..bee666467a 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -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