From d64cf0e50ec1c96357f08c6e68299375651993b0 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Sun, 21 Apr 2024 00:31:12 -0400 Subject: [PATCH] stats.lua: make page 1 scrollable This makes page 1 scrollable with up and down keys. The trick here to avoid a large append parameter refactoring is to make the append function add the table index only if the newline character is not empty. Otherwise, new strings are appended to the existing string. --- player/lua/stats.lua | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/player/lua/stats.lua b/player/lua/stats.lua index d2fae46f8f..cca9a496f3 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -263,7 +263,10 @@ local function append(s, str, attr) attr.prefix = attr.prefix or "" attr.no_prefix_markup = attr.no_prefix_markup or false attr.prefix = attr.no_prefix_markup and attr.prefix or b(attr.prefix) - s[#s+1] = format("%s%s%s%s%s%s", attr.nl, attr.indent, + + local index = #s + (attr.nl == "" and 0 or 1) + s[index] = s[index] or "" + s[index] = s[index] .. format("%s%s%s%s%s%s", attr.nl, attr.indent, attr.prefix, attr.prefix_sep, no_ASS(str), attr.suffix) return true end @@ -640,7 +643,7 @@ end local function add_file(s) - append(s, "", {prefix="File:", nl="", indent=""}) + append(s, "", {prefix="File:", indent=""}) append_property(s, "filename", {prefix_sep="", nl="", indent=""}) if not (mp.get_property_osd("filename") == mp.get_property_osd("media-title")) then append_property(s, "media-title", {prefix="Title:"}) @@ -884,7 +887,7 @@ local function add_video_out(s) return end - append(s, "", {prefix=o.nl .. o.nl .. "Display:", nl="", indent=""}) + append(s, "", {prefix="Display:", nl=o.nl .. o.nl, indent=""}) append(s, vo, {prefix_sep="", nl="", indent=""}) append_property(s, "display-names", {prefix_sep="", prefix="(", suffix=")", no_prefix_markup=true, nl="", indent=" "}) @@ -937,7 +940,7 @@ local function add_video(s) return end - append(s, "", {prefix=o.nl .. o.nl .. "Video:", nl="", indent=""}) + append(s, "", {prefix="Video:", nl=o.nl .. o.nl, indent=""}) local track = mp.get_property_native("current-tracks/video") if track and append(s, track["codec-desc"], {prefix_sep="", nl="", indent=""}) then append(s, track["codec-profile"], {prefix="[", nl="", indent=" ", prefix_sep="", @@ -997,7 +1000,7 @@ local function add_audio(s) return (a == b or a == nil) and a or (a .. " ➜ " .. b) end - append(s, "", {prefix=o.nl .. o.nl .. "Audio:", nl="", indent=""}) + append(s, "", {prefix="Audio:", nl=o.nl .. o.nl, indent=""}) local track = mp.get_property_native("current-tracks/audio") if track then append(s, track["codec-desc"], {prefix_sep="", nl="", indent=""}) @@ -1137,14 +1140,16 @@ end -- Returns an ASS string with "normal" stats local function default_stats() - local stats = {} + local header, content = {}, {} eval_ass_formatting() - add_header(stats) - add_file(stats) - add_video_out(stats) - add_video(stats) - add_audio(stats) - return finalize_page({}, stats, false) + add_header(header) + local page = pages[o.key_page_1] + append(header, "", {prefix=format("%s:%s", page.desc, scroll_hint()), nl="", indent=""}) + add_file(content) + add_video_out(content) + add_video(content) + add_audio(content) + return finalize_page(header, content, true) end -- Returns an ASS string with extended VO stats @@ -1266,7 +1271,7 @@ local function cache_stats() append(stats, info["debug-low-level-seeks"], {prefix = "Media Seeks:"}) append(stats, info["debug-byte-level-seeks"], {prefix = "Stream Seeks:"}) - append(stats, "", {prefix=o.nl .. o.nl .. "Ranges:", nl="", indent=""}) + append(stats, "", {prefix="Ranges:", nl=o.nl .. o.nl, indent=""}) append(stats, info["bof-cached"] and "yes" or "no", {prefix = "Start Cached:"}) @@ -1306,7 +1311,7 @@ cache_recorder_timer:kill() -- Current page and : mapping curr_page = o.key_page_1 pages = { - [o.key_page_1] = { f = default_stats, desc = "Default" }, + [o.key_page_1] = { f = default_stats, desc = "Usual Statistics", scroll = true }, [o.key_page_2] = { f = vo_stats, desc = "Extended Frame Timings", scroll = true }, [o.key_page_3] = { f = cache_stats, desc = "Cache Statistics" }, [o.key_page_4] = { f = keybinding_info, desc = "Active Key Bindings", scroll = true },