diff --git a/DOCS/man/stats.rst b/DOCS/man/stats.rst index 21c0db5b69..d98470c61a 100644 --- a/DOCS/man/stats.rst +++ b/DOCS/man/stats.rst @@ -30,15 +30,24 @@ stats: 0 Internal stuff (scroll) ==== ================== +If stats were displayed by toggling, these key bindings are also active: + +==== ================== +ESC Close the stats +==== ================== + On pages which support scroll, these key bindings are also active: ==== ================== -UP Scroll one line up -DOWN Scroll one line down +UP Scroll one line up +DOWN Scroll one line down ==== ================== -Page 4 also binds ``/`` to search for input bindings by typing part of a binding -or command. +On page 4, these key bindings are also active: + +==== ================== +/ Search key bindings +==== ================== Configuration ------------- @@ -62,6 +71,8 @@ Configurable Options Default: 5 ``key_page_0`` Default: 0 +``key_exit`` + Default: ESC Key bindings for page switching while stats are displayed. diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 9366f40788..f73e69041a 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -24,6 +24,7 @@ local o = { key_scroll_up = "UP", key_scroll_down = "DOWN", key_search = "/", + key_exit = "ESC", scroll_lines = 1, duration = 4, @@ -135,6 +136,7 @@ local function init_buffers() end local cache_ahead_buf, cache_speed_buf local perf_buffers = {} +local process_key_binding local function graph_add_value(graph, value) graph.pos = (graph.pos % graph.len) + 1 @@ -1631,6 +1633,21 @@ local function unbind_search() mp.remove_key_binding("__forced_"..o.key_search) end +local function bind_exit() + -- Don't bind in oneshot mode because if ESC is pressed right when the stats + -- stop being displayed, it would unintentionally trigger any user-defined + -- ESC binding. + if not display_timer.oneshot then + mp.add_forced_key_binding(o.key_exit, "__forced_" .. o.key_exit, function () + process_key_binding(false) + end) + end +end + +local function unbind_exit() + mp.remove_key_binding("__forced_" .. o.key_exit) +end + local function update_scroll_bindings(k) if pages[k].scroll then bind_scroll() @@ -1660,6 +1677,7 @@ local function add_page_bindings() mp.add_forced_key_binding(k, "__forced_"..k, a(k), {repeatable=true}) end update_scroll_bindings(curr_page) + bind_exit() end @@ -1670,10 +1688,11 @@ local function remove_page_bindings() end unbind_scroll() unbind_search() + unbind_exit() end -local function process_key_binding(oneshot) +process_key_binding = function(oneshot) reset_scroll_offsets() -- Stats are already being displayed if display_timer:is_enabled() then