Skip to content

Commit

Permalink
stats.lua: make page 0 scrollable
Browse files Browse the repository at this point in the history
This makes page 0 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.
  • Loading branch information
na-na-hi committed Apr 21, 2024
1 parent d8924b0 commit d67e3bd
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions player/lua/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:"})
Expand Down Expand Up @@ -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=" "})
Expand Down Expand Up @@ -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="",
Expand Down Expand Up @@ -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=""})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:"})
Expand Down Expand Up @@ -1306,7 +1311,7 @@ cache_recorder_timer:kill()
-- Current page and <page key>:<page function> 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 },
Expand Down

0 comments on commit d67e3bd

Please sign in to comment.