summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
authorGuido Cella <guido@guidocella.xyz>2024-03-21 20:09:22 +0100
committerKacper Michajłow <kasper93@gmail.com>2024-04-18 01:17:53 +0200
commit8a4ecda94074c27501b52bbc6e7d44828f5e4f7a (patch)
treebcb1baf80b9bc461e0a4cab3d2b6235376869994 /player/lua
parent7cfd369ffb8cb5ddfe2e88d10d6d648f8a9db60a (diff)
downloadmpv-8a4ecda94074c27501b52bbc6e7d44828f5e4f7a.tar.bz2
mpv-8a4ecda94074c27501b52bbc6e7d44828f5e4f7a.tar.xz
stats.lua: filter input bindings by typing them
This lets you press / in page 4 of the stats and type a keybinding or part of its command to filter it by using mp.input. This works badly without a VO because both stats.lua and console.lua use show-text and only one can be displayed at a time, but it's still better than not having the search available at all.
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/stats.lua69
1 files changed, 66 insertions, 3 deletions
diff --git a/player/lua/stats.lua b/player/lua/stats.lua
index d07e4dc123..44bda01e18 100644
--- a/player/lua/stats.lua
+++ b/player/lua/stats.lua
@@ -9,6 +9,7 @@
local mp = require 'mp'
local options = require 'mp.options'
local utils = require 'mp.utils'
+local input = require 'mp.input'
-- Options
local o = {
@@ -21,6 +22,7 @@ local o = {
-- For pages which support scrolling
key_scroll_up = "UP",
key_scroll_down = "DOWN",
+ key_search = "/",
scroll_lines = 1,
duration = 4,
@@ -108,6 +110,7 @@ local cache_recorder_timer = nil
local curr_page = o.key_page_1
local pages = {}
local scroll_bound = false
+local searched_text
local tm_viz_prev = nil
-- Save these sequences locally as we'll need them a lot
local ass_start = mp.get_property_osd("osd-ass-cc/0")
@@ -289,8 +292,12 @@ local function sorted_keys(t, comp_fn)
return keys
end
-local function scroll_hint()
- local hint = format("(hint: scroll with %s/%s)", o.key_scroll_up, o.key_scroll_down)
+local function scroll_hint(search)
+ local hint = format("(hint: scroll with %s/%s", o.key_scroll_up, o.key_scroll_down)
+ if search then
+ hint = hint .. " and search with " .. o.key_search
+ end
+ hint = hint .. ")"
if not o.use_ass then return " " .. hint end
return format(" {\\fs%s}%s{\\fs%s}", o.font_size * 0.66, hint, o.font_size)
end
@@ -444,6 +451,11 @@ local function get_kbinfo_lines()
(bind.is_weak == active[bind.key].is_weak and
bind.priority > active[bind.key].priority)
) and not bind.cmd:find("script-binding stats/__forced_", 1, true)
+ and bind.section ~= "input_forced_console"
+ and (
+ searched_text == nil or
+ (bind.key .. bind.cmd):lower():find(searched_text, 1, true)
+ )
then
active[bind.key] = bind
end
@@ -1122,7 +1134,7 @@ local function keybinding_info(after_scroll, bindlist)
local page = pages[o.key_page_4]
eval_ass_formatting()
add_header(header)
- append(header, "", {prefix=format("%s:%s", page.desc, scroll_hint()), nl="", indent=""})
+ append(header, "", {prefix=format("%s:%s", page.desc, scroll_hint(true)), nl="", indent=""})
header = {table.concat(header)}
if not kbinfo_lines or not after_scroll then
@@ -1351,12 +1363,58 @@ local function unbind_scroll()
scroll_bound = false
end
end
+
+local function filter_bindings()
+ input.get({
+ prompt = "Filter bindings:",
+ opened = function ()
+ -- This is necessary to close the console if the oneshot
+ -- display_timer expires without typing anything.
+ searched_text = ""
+ end,
+ edited = function (text)
+ reset_scroll_offsets()
+ searched_text = text:lower()
+ print_page(curr_page)
+ if display_timer.oneshot then
+ display_timer:kill()
+ display_timer:resume()
+ end
+ end,
+ submit = input.terminate,
+ closed = function ()
+ searched_text = nil
+ if display_timer:is_enabled() then
+ print_page(curr_page)
+ if display_timer.oneshot then
+ display_timer:kill()
+ display_timer:resume()
+ end
+ end
+ end,
+ })
+end
+
+local function bind_search()
+ mp.add_forced_key_binding(o.key_search, "__forced_"..o.key_search, filter_bindings)
+end
+
+local function unbind_search()
+ mp.remove_key_binding("__forced_"..o.key_search)
+end
+
local function update_scroll_bindings(k)
if pages[k].scroll then
bind_scroll()
else
unbind_scroll()
end
+
+ if k == o.key_page_4 then
+ bind_search()
+ else
+ unbind_search()
+ end
end
-- Add keybindings for every page
@@ -1383,6 +1441,7 @@ local function remove_page_bindings()
mp.remove_key_binding("__forced_"..k)
end
unbind_scroll()
+ unbind_search()
end
@@ -1445,6 +1504,10 @@ display_timer = mp.add_periodic_timer(o.duration,
function()
if display_timer.oneshot then
display_timer:kill() ; clear_screen() ; remove_page_bindings()
+ -- Close the console only if it was opened for searching bindings.
+ if searched_text then
+ input.terminate()
+ end
else
print_page(curr_page)
end